使用以下代码,一切正常:
from selenium import webdriver
driver = webdriver.PhantomJS(executable_path='/usr/local/bin/phantomjs', service_args=['--ignore-ssl-errors=true', '--ssl-protocol=TLSv1'])
driver.get('https://myurl.com')
现在我正在使用这个页面,一切都运行得很好,直到我完成并且我想用以下命令终止会话:
driver.quit()
执行此操作后,Python会抛出此异常:
Traceback (most recent call last):
File "/home/pi/Public/Python/changedet/changedet.py", line 20, in <module>
elba.elba(3)
File "/home/pi/Public/Python/changedet/listener/elba.py", line 18, in __init__
self.performCheck();
File "/home/pi/Public/Python/changedet/listener/elba.py", line 70, in performCheck
driver.quit()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/phantomjs/webdriver.py", line 76, in quit
self.service.stop()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.py", line 162, in stop
self.process.terminate()
AttributeError: 'Popen' object has no attribute 'terminate'
如果有人知道如何摆脱这种异常,我会非常高兴。
答案 0 :(得分:0)
我记得很难设置它。不知道具体的错误,但是我让它使用虚拟显示来伪造&#34; head&#34;在Ubuntu 14中。
这对我有用:
from pyvirtualdisplay import Display
from selenium import webdriver
display = Display(visible=0, size=(2000, 1600))
display.start()
driver = webdriver.Chrome()
driver.get("http://google.com")
display.stop()
driver.quit()
有点hacky,但值得一试。
干杯