繁体   English   中英

使用带有 chrome 的 Selenium Webdriver 时出错

[英]Errror with using Selenium Webdriver with chrome

from bs4 import BeautifulSoup, SoupStrainer
from selenium import webdriver
from selenium.webdriver import chrome
from selenium.webdriver.chrome.options import Options



url = 'https://...'
options = webdriver.ChromeOptions()
options.add_argument('--no-sandbox')
options.add_argument("--headless")
driver = webdriver.Chrome('path')
driver.get(url)

错误:

Traceback (most recent call last):
  File "", line 20, in <module>
    driver.get(EPL_url)
  File "", line 333, in get
    self.execute(Command.GET, {'EPL_url': url})
  File "", line 321, in execute
    self.error_handler.check_response(response)
  File "", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown command: unknown command: session/9df33bd6f0e57084300c81738cf6c2d5/EPL_url

我试图查看所有潜在的错误,但一无所获。 烦人的事情是,“driver.get()”function 早些时候工作得很好。 在我更改了 URL 的变量名之后,它似乎才被打乱了。 我真的不知道该怎么做,需要让这段代码恢复运行。 请帮助我解决上述错误,以便我纠正它。! 将不胜感激。

此问题可能是由于 chrome 驱动程序的路径。 这里有一个更简单的解决方案:安装python-chrome驱动package,在你的脚本中导入,就大功告成了。

一步步:

  1. pip 安装 chromedriver-binary
  2. 导入 package
from selenium import webdriver
import chromedriver_binary  # Adds chromedriver binary to path

driver = webdriver.Chrome()
driver.get("http://www.python.org")

参考: https://pypi.org/project/chromedriver-binary/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM