【发布时间】:2019-10-06 07:31:57
【问题描述】:
我正在尝试自动化一些我在网上进行的日常工作,并获得一些网络抓取方面的经验。我看到一些关于 Selenium 和 Python 对初学者有好处的东西,我想我会试一试。我最终得到了一个简单的脚本,可以在我的家用计算机上运行,但它在我提供的路径中找不到 Chrome 二进制文件,我不知道该怎么做。
我使用它来将我的 PATH 环境变量设置为包含我的 chromedriver https://youtu.be/dz59GsdvUF8的目录
我从https://sites.google.com/a/chromium.org/chromedriver/下载了ChromeDriver 74.0.3729.6(最新稳定版)
我正在使用 python3、Visual Studio 代码和 Ubuntu,如果其中有任何一个重要的话。
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
#Stack overflow said to try this but could not make it work
#opts = webdriver.ChromeOptions()
#opts.binary_location = "C:\webdrivers\chromedriver.exe"
#browser = webdriver.Chrome(chrome_options=opts)
#this is where my chrome is
#C:\Users\tucker.steven2\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Virtual Programs\Google Chrome\Chrome v62
#I have a chromedriver in the same directory as my python code
browser = webdriver.Chrome('chromedriver.exe')
browser.get(https://www.something.com/) #just a generic site
browser.quit()
我的预期结果是打开一个 chrome 窗口到 Hulu 的网站,我得到的错误是:
selenium.common.exceptions.WebDriverException:消息:未知错误:找不到 Chrome 二进制文件 (驱动信息:chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Windows NT 10.0.16299 x86_64)
【问题讨论】:
标签: python-3.x selenium selenium-webdriver