简体   繁体   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)

Error:错误:

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

I have tried to look at all the potential errors around this and have found nothing.我试图查看所有潜在的错误,但一无所获。 The annoying things is, the "driver.get()" function was working perfectly earlier.烦人的事情是,“driver.get()”function 早些时候工作得很好。 It only seemed to have been disrupted after I had changed the variable name of the URL.在我更改了 URL 的变量名之后,它似乎才被打乱了。 I seriously do not know what to do and need to get this code back up and running.我真的不知道该怎么做,需要让这段代码恢复运行。 Please help me with the above error so I can rectify this.!请帮助我解决上述错误,以便我纠正它。! It would be much appreciated.将不胜感激。

This issue can be because of the path of the chrome driver.此问题可能是由于 chrome 驱动程序的路径。 Here's a simpler solution: install the python-chrome drive package, import it in your script, and it's done.这里有一个更简单的解决方案:安装python-chrome驱动package,在你的脚本中导入,就大功告成了。

Step by step:一步步:

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

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

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

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

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