我正在尝试使用Selenium和BeautifulSoup抓取Google Chrome扩展商店评论。然而,即使使用最新版本的Chromedriver,我似乎无法启动和运行Selenium,这似乎解决了其他人在这个网站上询问相同问题的问题。一个空白的Chrome窗口将短暂打开,然后关闭。这是我得到的追溯:
Traceback (most recent call last):
File "scrape_chrome_reviews.py", line 5, in <module>
driver = webdriver.Chrome(chromedriver)
File "/Users/serenity/anaconda/lib/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 69, in __init__
desired_capabilities=desired_capabilities)
File "/Users/serenity/anaconda/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 92, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/Users/serenity/anaconda/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 179, in start_session
response = self.execute(Command.NEW_SESSION, capabilities)
File "/Users/serenity/anaconda/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 234, in execute
response = self.command_executor.execute(driver_command, params)
File "/Users/serenity/anaconda/lib/python2.7/site-packages/selenium/webdriver/remote/remote_connection.py", line 408, in execute
return self._request(command_info[0], url, body=data)
File "/Users/serenity/anaconda/lib/python2.7/site-packages/selenium/webdriver/remote/remote_connection.py", line 440, in _request
resp = self._conn.getresponse()
File "/Users/serenity/anaconda/lib/python2.7/httplib.py", line 1132, in getresponse
response.begin()
File "/Users/serenity/anaconda/lib/python2.7/httplib.py", line 453, in begin
version, status, reason = self._read_status()
File "/Users/serenity/anaconda/lib/python2.7/httplib.py", line 417, in _read_status
raise BadStatusLine(line)
httplib.BadStatusLine: ''
我正在运行的代码就是这样:
from selenium import webdriver
chromedriver = '/usr/local/Cellar/chromedriver/2.27/bin/chromedriver'
driver = webdriver.Chrome(chromedriver)
driver.quit()
有什么建议吗?我真的很难过。
答案 0 :(得分:1)
下载最新版本的chromedriver并将其放置在项目中的某个位置并调用它而不是on bin文件。
from selenium import webdriver
driver = webdriver.Chrome("/path/to/chromedriver")