【发布时间】:2020-12-30 15:43:04
【问题描述】:
我正在尝试使用 Selenium 模块创建一个网络爬虫。用户拥有 Mac 系统。我的项目文件夹包括
./scraper The main file
./lib The folder where chromedriver_mac is placed
./src py file is here
所以,我使用 os.chdir() 返回一个文件夹,然后找到“lib”文件夹。
os.chdir("..")
os.chdir("lib")
browser = webdriver.Chrome("chromedriver_mac")
它在 Windows 上完美运行。但是,当涉及到 MAC 时,它会抛出异常。
FileNotFoundError: [Errno 2] No such file or directory: 'chromedriver_mac'
.
.
During handling of the above exception, another exception occurred:
.
.
WebDriverException(selenium.common.exceptions.WebDriverException: Message: 'chromedriver_mac' executable needs to be in PATH.
我需要找到一个使用相对路径的解决方案。绝对路径对我来说似乎不是解决方案,因为会有不同的用户。
谢谢。
【问题讨论】:
-
你试过打电话给
browser = webdriver.Chrome("../lib/chromedriver_mac")吗?并不是说它在逻辑上与您正在做的事情有任何不同,但操作系统差异可能会令人痛苦,这应该普遍适用。 -
@ABear 它没有用。当我将绝对位置设置为“/Users/xxx/Downloads/chromedriver”时,它的工作原理很奇怪。我真的迷路了。
-
是在下载中还是在../lib 中?
标签: python macos selenium webdriver