提问人:Einreinfall 提问时间:4/26/2020 更新时间:4/26/2020 访问量:1328
Selenium WebDriverException:无法访问 chrome
Selenium WebDriverException: chrome not reachable
问:
我正在尝试使用 Python 抓取 Javascript 页面。看到 PhantomJS 已被弃用,我正在尝试使用无头 Chrome 网络驱动程序加载页面,但无济于事。
驱动程序已加载,但代码大多在等待期间或检索页面源时崩溃。
法典:
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from webdriver_manager.chrome import ChromeDriverManager
def fetch(search):
BASE_URL = 'https://ko.dict.naver.com/#/search?query='
DELAY = 10
html = None
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
driver = webdriver.Chrome(ChromeDriverManager().install(), chrome_options=options)
search_url = BASE_URL + search
driver.get(search_url)
try:
WebDriverWait(driver, DELAY).until(EC.presence_of_element_located((By.ID, 'content')))
except TimeoutException:
print('Took too long to load.')
else:
html = driver.page_source
finally:
driver.quit()
return html
堆栈跟踪:
Traceback (most recent call last):
File "fetch.py", line 44, in <module>
test = fetch(s)
File "fetch.py", line 31, in fetch
WebDriverWait(driver, DELAY).until(EC.presence_of_element_located((By.ID, 'content')))
File "/home/jrmanrique/.virtualenvs/nltk-kor/lib/python3.6/site-packages/selenium/webdriver/support/wait.py", line 71, in until
value = method(self._driver)
File "/home/jrmanrique/.virtualenvs/nltk-kor/lib/python3.6/site-packages/selenium/webdriver/support/expected_conditions.py", line 64, in __call__
return _find_element(driver, self.locator)
File "/home/jrmanrique/.virtualenvs/nltk-kor/lib/python3.6/site-packages/selenium/webdriver/support/expected_conditions.py", line 415, in _find_element
raise e
File "/home/jrmanrique/.virtualenvs/nltk-kor/lib/python3.6/site-packages/selenium/webdriver/support/expected_conditions.py", line 411, in _find_element
return driver.find_element(*by)
File "/home/jrmanrique/.virtualenvs/nltk-kor/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 978, in find_element
'value': value})['value']
File "/home/jrmanrique/.virtualenvs/nltk-kor/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/jrmanrique/.virtualenvs/nltk-kor/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: chrome not reachable
(Session info: headless chrome=81.0.4044.122)
系统信息:
Ubuntu 18.04 on Windows
Google Chrome 81.0.4044.122
Chromedriver 81.0.4044.69
Selenium 3.141.0
答: 暂无答案
评论
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
apt-get -y update
apt-get install -y google-chrome-stable
ln -s /usr/bin/chromium-browser && chmod 777 /usr/bin/chromium-browser
chromedriver
/usr/local/bin