【发布时间】:2019-09-28 14:58:35
【问题描述】:
我目前正在尝试实现一个抓取工具,它会每天检查两次是否某些 PDF 更改名称。不幸的是,它需要网站操作才能找到 pdf,所以我认为最好的解决方案是 Selenium 和 AWS Lambda 的组合。
一开始我关注的是this 教程。我已经完成了教程,但在 Lambda 中遇到了这个错误:
START RequestId: 18637c6d-ea75-40ee-8789-374654700b99 Version: $LATEST
Starting google.com
Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
: WebDriverException
Traceback (most recent call last):
File "/var/task/lambda_function.py", line 46, in lambda_handler
driver = webdriver.Chrome(chrome_options=chrome_options)
File "/var/task/selenium/webdriver/chrome/webdriver.py", line 68, in __init__
self.service.start()
File "/var/task/selenium/webdriver/common/service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
这个错误是别人遇到的,作者通过链接this堆栈溢出页面“解决”。我已经尝试过它,但所有答案都与在桌面上使用无头铬而不是 AWS lambda 有关。
我尝试了一些更改无济于事。
1) 将 chromedriver 和 headless-chromium 更改为 .exe 文件
2) 更改这行代码以包含 executable_path
driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=os.getcwd() + "/bin/chromedriver.exe")
如果能帮助 selenium 和 aws lambda 一起工作,我们将不胜感激。
【问题讨论】:
-
您是否已将下载的 chromium 文件添加为部署包的一部分,如果是,请尝试将驱动程序命令的路径更改为以下内容:
driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=os.getcwd() + "./chromedriver.exe") -
很抱歉回复晚了,但我尝试使用“./”但仍然收到相同的错误
标签: python selenium aws-lambda