因此,我尝试在aws lambda运行时Python3.6中使用firefox,我已按以下顺序使用层添加了我的依赖项:selenium3.14,geckodriver25和firefox 69二进制文件,以创建我的Webdriver实例,我正在使用此代码: / p>
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
path = '/tmp/'
def start_browser(url, headless=True):
fp = webdriver.FirefoxProfile()
options = Options()
if headless==True:
options.headless = True
fp.set_preference("browser.preferences.instantApply",True)
fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "text/xls, application/vnd.ms-excel")
fp.set_preference("browser.helperApps.alwaysAsk.force",False)
fp.set_preference("browser.download.dir", path)
fp.set_preference("browser.download.folderList", 2)
fp.set_preference("browser.download.manager.showWhenStarting", False)
browser = webdriver.Firefox(
options=options,
executable_path="/opt/geckodriver",
log_path="/tmp/geckodriver.log",
firefox_profile=fp,
firefox_binary="/opt/firefox/firefox"
)
browser.get(url)
return browser
我的函数执行了,但是从AWS控制台进行测试时得到了这个响应
{
"message": "Your function executed unsuccessfully!",
"event": "Message: 'geckodriver' executable needs to be in PATH. \n"
}
答案 0 :(得分:0)
我需要将lambda依赖关系的路径从"/opt/my_dependency"
更改为"/opt/python/my_dependency"