2018年07月28日 11:22:52 閱讀數:196 標籤: webdriverchromefirefoxDisplay 更多python
我的分類: 小bugweb
#!/usr/bin/python
chrome
# -*- coding: utf-8 -*-
bootstrap
from selenium import webdriver
session
driver = webdriver.Firefox()
多線程
driver.get("https://www.baidu.com")
測試
Traceback (most recent call last):
spa
File "maimai_web.py", line 14, in <module>
.net
driver = webdriver.Firefox()
firefox
File "/usr/local/python3.6/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 152, in __init__
keep_alive=True)
File "/usr/local/python3.6/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 98, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/usr/local/python3.6/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 188, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/python3.6/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 256, in execute
self.error_handler.check_response(response)
File "/usr/local/python3.6/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status 1
#!/usr/bin/python
# -*- coding: utf-8 -*-
from pyvirtualdisplay import Display
from selenium import webdriver
display = Display(visible=0, size=(1920, 1080))
display.start()
driver = webdriver.Firefox()
driver.get("https://www.baidu.com")
運行ok,搞定!
採用多線程調用webdriver時候,偶爾會出現這樣的錯:selenium.common.exceptions.WebDriverException: Message: connection refused
Exception in thread Thread-2:
Traceback (most recent call last):
File "/usr/local/python3.6/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/usr/local/python3.6/lib/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "maimai_tran_account_driver.py", line 591, in debug
t = TrainAccount(count,lock)
File "maimai_tran_account_driver.py", line 32, in __init__
self.chrome = webdriver.Firefox()
File "/usr/local/python3.6/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 152, in __init__
keep_alive=True)
File "/usr/local/python3.6/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 98, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/usr/local/python3.6/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 188, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/python3.6/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 256, in execute
self.error_handler.check_response(response)
File "/usr/local/python3.6/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: connection refused
查看geckodriver.log具體報錯信息。
後續的坑繼續填。。。