首页 > 解决方案 > Python:无法通过网络浏览器传递 url

问题描述

我正在尝试使用 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)

提前致谢。

标签: pythonselenium

解决方案


我通过安装 webdrivers 解决了这个问题。

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)

推荐阅读