Я пытаюсь очистить страницу Javascript с помощью Python. Видя, что Phantom JS уже устарел, я пытаюсь использовать безголовый 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
Stacktrace:
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