Chrome 我想在python中使用Selenium进行抓取

7hiiyaii  于 12个月前  发布在  Go
关注(0)|答案(1)|浏览(97)

我有Chrome -版本116.0.5845.97(正式版)(64位).我在同一个文件夹中安装的ChromeDriver版本是116.0.5845.96。我找不到完全相同的版本。

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

try:
    driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))#, options=options
 
except Exception as e:
    print("An error occurred:", str(e))

当我在Python中运行代码时,我得到一条消息:
错误信息:错误信息找不到Chrome二进制文件

vbopmzt1

vbopmzt11#

我不确定版本,如果它们都更新了,那就好了,下面是我初始化driver的方法:

from selenium import webdriver

# Specify the path to the Chrome driver executable(you need to download and put it somewhere)
chrome_driver_path = "C:\\Users\\akram\\Desktop\\Work\\chromedriver-win64\\chromedriver.exe"
# Initialize the Chrome WebDriver
service = webdriver.chrome.service.Service(chrome_driver_path)
driver = webdriver.Chrome(service=service)
url = "URL_TO_SCRAP"
driver.get(url)

安装webdriver,如果它没有:pip install selenium

相关问题