lunix中启动webdriver时报错一:
测试代码为:
代码语言:javascript复制
-
#!/usr/bin/python
-
# -*- coding: utf-8 -*-
-
from selenium import webdriver
-
driver = webdriver.Firefox()
-
driver.get("https://www.baidu.com")
运行报错信息如下:
代码语言:javascript复制
-
Traceback (most recent call last):
-
File "maimai_web.py", line 14, in <module>
-
driver = 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: Process unexpectedly closed with status 1
处理方法:
代码语言:javascript复制
-
#!/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实例化报错
采用多线程调用webdriver时候,偶尔会出现这样的错:selenium.common.exceptions.WebDriverException: Message: connection refused
代码语言:javascript复制
-
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具体报错信息。
后续的坑继续填。。。
(adsbygoogle = window.adsbygoogle || []).push({});