【问题标题】:Python: Unable to pass the url through web browserPython:无法通过网络浏览器传递 url
【发布时间】:2020-08-13 12:52:52
【问题描述】:

我正在尝试使用 python selenium 抓取网络数据,但是当我运行能够打开浏览器的 py 代码但它没有将 url 传递到网络浏览器时,下面是我正在使用的示例代码。

import requests
from selenium import webdriver

Chromepath = r"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"

url = "https://climate.weather.gc.ca/historical_data/search_historic_data_e.html"
driver = webdriver.Chrome(Chromepath)
driver.get(url)

提前致谢。

【问题讨论】:

    标签: python selenium


    【解决方案1】:

    here 下载 Chrome 驱动程序,然后您可以尝试以下操作:

    import time
    from selenium import webdriver
    
    url = "https://climate.weather.gc.ca/historical_data/search_historic_data_e.html"
    driver = webdriver.Chrome('/path/to/chromedriver') # Optional argument, if not specified will search path.
    driver.get(url);
    time.sleep(5) # Let the user actually see something!
    driver.quit()
    

    Read more here.

    【讨论】:

    • 感谢您对 Alpha 的回复。祝您有美好的一天。
    【解决方案2】:

    我通过安装网络驱动程序解决了这个问题。

    import requests
    from selenium import webdriver
    
    # Chromepath = r"C:\\Program Files x86)\\Google\\Chrome\\Application\\chrome.exe"
    Chromepath = r"C:\\Ecomm\\chromedriver_win32\\chromedriver.exe"
    url = "https://climate.weather.gc.ca/historical_data/search_historic_data_e.html"
    driver = webdriver.Chrome(Chromepath)
    driver.get(url)
    

    【讨论】:

      猜你喜欢
      • 2014-02-24
      • 2018-01-11
      • 1970-01-01
      • 2013-02-14
      • 1970-01-01
      • 1970-01-01
      • 2015-03-31
      • 2019-11-25
      • 1970-01-01
      相关资源
      最近更新 更多