Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Webdriver phantomjs在单击时不再跟随链接_Python_Selenium_Selenium Webdriver_Phantomjs - Fatal编程技术网

Python Webdriver phantomjs在单击时不再跟随链接

Python Webdriver phantomjs在单击时不再跟随链接,python,selenium,selenium-webdriver,phantomjs,Python,Selenium,Selenium Webdriver,Phantomjs,我使用一个简单的webdriver phantomjs脚本来更新preloved.co.uk上的一些广告。直到最近,这个脚本一直工作得很好,但在单击登录链接后出现了“Click submitted but load failed”(单击提交但加载失败)错误,导致脚本失败。根据指南,我将我的phantomjs版本更新为最新的稳定版本1.9.7。但是,现在登录单击似乎也没有注册,页面也不会重新加载 第一步是进入登录表单页面 from selenium import webdriver br = we

我使用一个简单的webdriver phantomjs脚本来更新preloved.co.uk上的一些广告。直到最近,这个脚本一直工作得很好,但在单击登录链接后出现了“Click submitted but load failed”(单击提交但加载失败)错误,导致脚本失败。根据指南,我将我的phantomjs版本更新为最新的稳定版本1.9.7。但是,现在登录单击似乎也没有注册,页面也不会重新加载

第一步是进入登录表单页面

from selenium import webdriver
br = webdriver.PhantomJS(service_log_path='/path/to/logfile.log')
url = "http://www.preloved.co.uk"
br.get(url)

# Go to login page
login_button = br.find_element_by_xpath('//div[@id="header-status-login"]/a')
login_button.click()
通常情况下(例如,如果您将浏览器行替换为
br=webdriver.Firefox()
),这将导致重新加载到登录页面,脚本将从那里继续,但现在看来,单击根本不会加载新页面,
br.当前的\u url
仍然是“”

为什么这个负载不起作用

即使我提取href并执行显式GET,它似乎也不会跟随并重新加载:

newurl=login_button.get_attribute('href')
br.get(newurl)

br.当前url仍然是“”。

登录页面通过https进行保护。最近,POODLE漏洞迫使网站从SSLv3迁移到https,但由于PhantomJS使用登录页面,因此无法加载。另见

这可以通过将
--ssl protocol=tlsv1
--ssl protocol=any
传递到PhantomJS或将PhantomJS升级到至少1.9.8版来解决。似乎在Selenium的python绑定中可以使用
service_args
参数

在PhantomJS中,
服务参数
无法从
WebDriver
传递到
服务
。你可以把它分类

from selenium import webdriver
from selenium.webdriver.phantomjs.service import Service
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver

class PhantomJSService(webdriver.PhantomJS):
    def __init__(self, executable_path="phantomjs", port=0,
                 desired_capabilities=DesiredCapabilities.PHANTOMJS,
                 service_args=None, service_log_path=None):

        self.service = Service(executable_path, 
                               port=port, service_args=service_args,
                               log_path=service_log_path)
        self.service.start()

        try:
            RemoteWebDriver.__init__(self,
                command_executor=self.service.service_url,
                desired_capabilities=desired_capabilities)
        except:
            self.quit()
            raise 

这似乎包含了设置这些选项所需的参数。

我明白了,谢谢!你能不能说一些关于我如何在上面的小脚本中实现这个猴子补丁的更多信息……我添加了子类而不是猴子补丁。我现在看到您使用了
服务\u日志\u路径
。它的日志记录正确吗?首先,`br=PhantomJSService(service_args=['--ssl protocol=any',]`与子类配合得很好,谢谢。至于日志记录,我不太确定现在如何处理
service\u log\u path
,因为将其作为arg传递给
PhantomJSService
失败,关键字意外,在服务参数列表中传递它也会失败,因为
无法连接到GhostDriver
服务日志路径=None
添加到您的
初始化参数,以及
日志路径
自助服务=service(可执行路径,端口=端口,服务日志路径=服务日志路径)
似乎起作用了这应该可以解开谜团了它刚刚在
\uuuuu init\uuuuuuuuupy.py中被重命名了