【问题标题】:Selenium webscraping, open chrome failSelenium webscraping,打开chrome失败
【发布时间】:2017-10-01 19:15:57
【问题描述】:

我正在尝试从网站上抓取。
我正在尝试通过脚本使用 chromedriver 打开一个 url。它确实打开了chrome,但没有插入url。这是我的代码:

from selenium import webdriver
path_to_chromedriver = '/Users/***/Downloads/chromedriver'
browser = webdriver.Chrome(executable_path = path_to_chromedriver)

url = 'https://www.lexisnexis.com/hottopics/lnacademic/?verb=sf&sfi=AC00NBGenSrch'
browser.get(url)

我收到以下错误:

Traceback (most recent call last):
  File "/Users/***/Downloads/test.py", line 6, in <module>
    browser.get(url)
  File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 320, in get
    self.execute(Command.GET, {'url': url})
  File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 308, in execute
    self.error_handler.check_response(response)
  File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Runtime.executionContextCreated has invalid 'context': {"auxData":{"frameId":"31081.1","isDefault":true},"id":1,"name":"","origin":"://"}
  (Session info: chrome=61.0.3163.100)
  (Driver info: chromedriver=2.9.248307,platform=Mac OS X 10.9.5 x86_64)

我该怎么做才能插入网址?

【问题讨论】:

  • 我建议您检查您正在使用的 chrome 驱动器,以及是否与您的 chrome 版本完全兼容;无论如何,我将 chromedrive.exe 添加到 Windows 路径系统,而不是在代码中指定路径,它解决了我很多问题

标签: python google-chrome selenium


【解决方案1】:

不完全确定错误的原因,但我肯定会建议下载更新版本的chromedriver

https://sites.google.com/a/chromium.org/chromedriver/downloads

我还建议更新 selenium(从终端):pip install -U pip selenium

【讨论】:

    【解决方案2】:

    Chromedriver 2.9 版本已经过时了。

    尝试从here下载最新的chromedriver版本

    请注意,尽管releases list page 上的订单实际发布顺序看起来像

    • 2.0

    • 2.1

      ...

    • 2.9

    • 2.10

      ...

    • 2.32

    【讨论】:

      猜你喜欢
      • 2017-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-12
      • 2015-04-09
      相关资源
      最近更新 更多