gpt4 book ai didi

python - Selenium Chromedriver 错误 chrome 无法访问,但驱动程序可以正常工作

转载 作者:太空宇宙 更新时间:2023-11-03 19:51:03 24 4
gpt4 key购买 nike

我正在尝试使用 selenium 和 chromedriver 从网页获取页面内容。我在 Windows 上使用 Ubuntu 18.04 子系统。 driver.get 方法可以工作,但获取页面内容却不能。这是我的代码:

from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
import time
chromeOptions = webdriver.ChromeOptions()
chromeOptions.add_argument("--no-sandbox")
chromeOptions.add_argument("--headless")
driver = webdriver.Chrome(executable_path='/usr/bin/chromedriver', chrome_options=chromeOptions)
driver.get("https://www.bol.com/nl/")

print(driver.page_source)

这是我的错误:

Traceback (most recent call last):
File "product_tracker.py", line 10, in <module>
print(driver.page_source)
File "/home/tychokoster/py36/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 679, in page_source
return self.execute(Command.GET_PAGE_SOURCE)['value']
File "/home/tychokoster/py36/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/tychokoster/py36/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=79.0.3945.130)

真的不知道该怎么办了,我尝试更改 chromedriver 版本,也许问题出在使用子系统,但我不确定。

最佳答案

尝试使用:executable_path 和“absolute_path..upto..driver-EXE”,而不仅仅是一个目录。

例如:

driver = webdriver.Chrome("D:/Testing Purpose/Pycharm Testing/DemoProject/Driver/chromedriver.exe", chrome_options=chromeOptions)

我已经使用 Pycharm IDE 进行了测试,上面的代码工作正常。

谢谢...享受编码... enter image description here

关于python - Selenium Chromedriver 错误 chrome 无法访问,但驱动程序可以正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59842140/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com