我有这个代码
#!/usr/bin/env python
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
import time
driver = webdriver.Chrome()
错误发生在最后一行:driver = webdriver.Chrome() 它说:
Traceback (most recent call last):
File "/Users/Edison/Desktop/untitled folder/huamai_jacket1.py", line 9, in <module>
driver = webdriver.Chrome()
File "/Users/Edison/anaconda2/lib/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 61, in __init__
log_path=service_log_path)
File "/Users/Edison/anaconda2/lib/python2.7/site-packages/selenium/webdriver/chrome/service.py", line 42, in __init__
start_error_message="Please see https://sites.google.com/a/chromium.org/chromedriver/home")
File "/Users/Edison/anaconda2/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 42, in __init__
self.port = utils.free_port()
File "/Users/Edison/anaconda2/lib/python2.7/site-packages/selenium/webdriver/common/utils.py", line 36, in free_port
free_socket.bind(('0.0.0.0', 0))
File "/Users/Edison/anaconda2/lib/python2.7/socket.py", line 228, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 49] Can't assign requested address
Exception AttributeError: "'Service' object has no attribute 'log_file'" in <bound method Service.__del__ of <selenium.webdriver.chrome.service.Service object at 0x1049a93d0>> ignored
[Finished in 0.1s with exit code 1]
[shell_cmd: python -u "/Users/Edison/Desktop/untitled folder/huamai_jacket1.py"]
[dir: /Users/Edison/Desktop/untitled folder]
[path: /usr/bin:/bin:/usr/sbin:/sbin]
今天早上发生了事情,事情就在这发生之后,有时当我访问网站时甚至像google.com一样,ERR_ADDRESS_INVALID页面经常出现,我需要不断刷新以使页面回到常规网站。
这是因为driver.Chrome()不包含Chromedriver位置的PATH吗?我在今天之前使用了我的剧本一周,但一切都很完美。 请帮忙:(
答案 0 :(得分:0)
因此,如果您没有将路径作为&#34; webdriver.Chrome(&#39; path / to / chromedriver&#39;)&#34;的一部分传递。将沿着PATH环境变量进行搜索以找到它。所以我要做的第一件事是验证我的chromedriver在哪里。如果它不在$ PATH中,那么您可以将它放在usr / bin中并尝试再次运行。或者您可以将路径传递给.Chrome()中的chromedriver可执行文件。