Python 使用含硒的PhantomJS

Python 使用含硒的PhantomJS,python,selenium-webdriver,phantomjs,Python,Selenium Webdriver,Phantomjs,我想提高selenium性能(使用selenium python)。所以我想切换到无头浏览器,因为GUI不是必需的。 我为phantomJS设置路径变量并运行 driver = webdriver.PhantomJS() 在得到一个错误时我在初始化驱动程序时设置了路径和服务参数(经过几十个stackoverflow和google组) phantomjs_path = r"C:\Users\sachin.nandakumar\AppData\Local\Continuum\anaconda3\p

我想提高selenium性能(使用
selenium python
)。所以我想切换到无头浏览器,因为GUI不是必需的。 我为
phantomJS
设置路径变量并运行

driver = webdriver.PhantomJS()
在得到一个
错误时
我在初始化驱动程序时设置了路径和服务参数(经过几十个stackoverflow和google组)

phantomjs_path = r"C:\Users\sachin.nandakumar\AppData\Local\Continuum\anaconda3\phantomjs\bin\phantomjs.exe"
service_args = [ '--proxy=10.118.132.29:80', '--proxy-type=http',]     
driver = webdriver.PhantomJS(executable_path=phantomjs_path,service_args=service_args)    
但我仍然得到相同的错误。(下面详细说明错误)

后来我也尝试了
HtmlUnitDriver
,但同样的错误再次出现

无头浏览器在代理(公司防火墙?)后工作是否存在任何问题。或者,如果是关于一些身份验证问题,我没有找到解决方法

E
======================================================================
ERROR: test_start (__main__.TestWeb)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "...Crawler\crawl_core\src_main\run.py", line 26, in setUp
    driver =     webdriver.PhantomJS(executable_path=phantomjs_path,service_args=service_args)
  File "...\anaconda3\lib\site-packages\selenium\webdriver\phantomjs\webdriver.py", line 58, in __init__
desired_capabilities=desired_capabilities)
  File "...\anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 151, in __init__
self.start_session(desired_capabilities, browser_profile)
  File "...\anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 240, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
  File "...\anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 308, in execute
self.error_handler.check_response(response)
  File "...\anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 165, in check_response
raise exception_class(value)
selenium.common.exceptions.WebDriverException: Message: <HTML><HEAD>

<TITLE>Access Denied</TITLE>

</HEAD>

<BODY>

<FONT face="Helvetica">

<big><strong></strong></big><BR>

</FONT>

<blockquote>

<TABLE border=0 cellPadding=1 width="80%">

<TR><TD>

<FONT face="Helvetica">

<big>Access Denied (authentication_failed)</big>

<BR>

<BR>

</FONT>

</TD></TR>

<TR><TD>

<FONT face="Helvetica">

Your credentials could not be authenticated: "General authentication failure due to bad user ID or authentication token.". You will not be permitted access until your credentials can be verified.

</FONT>

</TD></TR>

<TR><TD>

<FONT face="Helvetica">

This is typically caused by an incorrect username and/or password, but could also be caused by network problems.

</FONT>

</TD></TR>

<TR><TD>

<FONT face="Helvetica" SIZE=2>

<BR>

For assistance, contact your network support team.

</FONT>

</TD></TR>

</TABLE>

</blockquote>

</FONT>

</BODY></HTML>
E
======================================================================
错误:测试开始(\uuuuu main\uuuuuu.TestWeb)
----------------------------------------------------------------------
回溯(最近一次呼叫最后一次):
文件“…Crawler\crawl\u core\src\u main\run.py”,第26行,在安装程序中
driver=webdriver.PhantomJS(可执行文件路径=PhantomJS路径,服务参数=service参数)
文件“..\anaconda3\lib\site packages\selenium\webdriver\phantomjs\webdriver.py”,第58行,在__
期望的_能力=期望的_能力)
文件“..\anaconda3\lib\site packages\selenium\webdriver\remote\webdriver.py”,第151行,在\uuu init中__
self.start\u会话(所需的\u功能、浏览器\u配置文件)
文件“…\anaconda3\lib\site packages\selenium\webdriver\remote\webdriver.py”,第240行,在启动会话中
响应=self.execute(Command.NEW_会话,参数)
文件“…\anaconda3\lib\site packages\selenium\webdriver\remote\webdriver.py”,第308行,在execute中
self.error\u handler.check\u响应(响应)
文件“…\anaconda3\lib\site packages\selenium\webdriver\remote\errorhandler.py”,第165行,在check\u响应中
引发异常\u类(值)
selenium.common.exceptions.WebDriverException:消息:
拒绝访问

访问被拒绝(身份验证失败)

无法对您的凭据进行身份验证:“由于用户ID或身份验证令牌错误,导致常规身份验证失败。”。在验证您的凭据之前,将不允许您访问。 这通常是由错误的用户名和/或密码引起的,但也可能是由网络问题引起的。
如需帮助,请联系您的网络支持团队。
PhantomJS不再处于积极开发中。因此,您不应该运行PhantomJS。切换到chrome,你应该会没事的。并检查代理是否需要身份验证


从这里获取chromedriver,

PhantomJS不再处于积极开发中。因此,您不应该运行PhantomJS。切换到chrome,你应该会没事的。并检查代理是否需要身份验证


从这里获取chromedriver,

在此之前,我从未在任何地方找到过该信息,但它非常方便!我换成了chrome无头浏览器。一旦我切换到它,我的第一个任务就是获取网页中的所有链接。但它不会获取所有链接。我认为页面加载有问题,所以我甚至将每个页面的超时设置为45s
driver.set\u page\u load\u timeout(45)
。还是不行!同样的代码也适用于firefox和chrome浏览器,但当切换到chrome的无头版本时就不行了!管理员一定做了一些更改。您需要在普通桌面上使用代理加载代理,而不使用代理。是。。chrome浏览器暂时帮我完成了任务!在此之前,我从未在任何地方找到过这个信息,但它非常方便!我换成了chrome无头浏览器。一旦我切换到它,我的第一个任务就是获取网页中的所有链接。但它不会获取所有链接。我认为页面加载有问题,所以我甚至将每个页面的超时设置为45s
driver.set\u page\u load\u timeout(45)
。还是不行!同样的代码也适用于firefox和chrome浏览器,但当切换到chrome的无头版本时就不行了!管理员一定做了一些更改。您需要在普通桌面上使用代理加载代理,而不使用代理。是。。chrome浏览器暂时帮我完成了任务!