python-selenium设置">Python selenium设置
selenium设置代理">selenium设置代理
python hljs ">ip = "xxx"
port = xxx
profile = webdriver.FirefoxProfile()
profile.set_preference('network.proxy.type', 1)
profile.set_preference('network.proxy.socks', ip)
profile.set_preference('network.proxy.socks_port', port)
profile.set_preference('network.proxy.ssl', ip)
profile.set_preference('network.proxy.ssl_port', port)
self.driver = webdriver.Firefox(executable_path=self.FIREFOX_PATH,firefox_profile=profile)
python-selenium错误">python selenium错误
问题1
【异常】selenium.common.exceptions.WebDriverException: Message: {“errorMessage”:“‘undefined’ is not an object
【解决办法】
设置用户代理设置导致了这个问题,可能是phantomjs不支持相应的代理。
错误代码:
python hljs "> dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap["phantomjs.page.settings.userAgent"] = (
"User-Agent,Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0")
driver = webdriver.PhantomJS(desired_capabilities=dcap)
driver = webdriver.PhantomJS()
更正做法:
python hljs "> driver = webdriver.PhantomJS()
问题 - KeyError问题
selenium中,把webdriver的firefox赋值给变量后,提示KeyError:’sessionId’ ?
出现这种情况的原因,可能是版本的问题。版本A 和 版本B 的中的key值发生了变化,所以系统交替的地方(firfox驱动 + selenium产生了不匹配)产生了问题。
解决办法:
pip install -U selenium
更新一下selenium
如果当前目录下有selenium目录,请更新一下,或删除掉
更新geckodriver.exe
参考:
关于该异常的一些讨论