【问题标题】:Working with PhantomJS with Selenium使用 Selenium 使用 PhantomJS
【发布时间】:2017-11-13 13:35:50
【问题描述】:

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

driver = webdriver.PhantomJS()

收到error 后,我在初始化驱动程序时设置了路径和服务参数(经过几十个 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>

【问题讨论】:

    标签: python selenium-webdriver phantomjs


    【解决方案1】:

    PhantomJS 不再处于积极开发阶段。所以你不应该运行 PhantomJS。切换到chrome,你应该没问题。并检查代理是否需要身份验证。

    从这里获取 chromedriver,https://sites.google.com/a/chromium.org/chromedriver/downloads

    【讨论】:

    • 在此之前我从未在任何地方找到该信息,但它非常方便!好吧,我切换到 chrome 无头浏览器。一旦我切换到它,我的第一个任务就是获取网页中的所有链接。但它不会获取所有链接。我认为这是页面加载的问题,所以我什至将每个页面的超时设置为 45s driver.set_page_load_timeout(45) 。还是行不通!相同的代码在 firefox 和 chrome 浏览器上工作,但在切换到无头版本的 chrome 时就不行了!
    • 管理员一定做了一些改变。您需要在使用代理和不使用代理的普通桌面上加载代理。
    • 是的.. chrome 浏览器暂时为我完成了这项工作!
    猜你喜欢
    • 2022-01-22
    • 2015-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-10
    • 1970-01-01
    • 1970-01-01
    • 2014-07-31
    相关资源
    最近更新 更多