我在 AWS Lambda 函式中使用以下代碼
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
def lambda_handler(event, context):
options = Options()
options.binary_location = '/opt/headless-chromium'
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--start-maximized')
options.add_argument('--start-fullscreen')
options.add_argument('--single-process')
options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome('/opt/chromedriver', options=options)
錯誤:
[錯誤] WebDriverException:訊息:服務 /opt/chromedriver 意外退出。狀態碼是:127
回溯(最后一次呼叫):檔案“/var/task/lambda_function.py”,第 27 行,在 lambda_handler driver = webdriver.Chrome('/opt/chromedriver', options=options) 檔案“/opt/python/lib /python3.8/site-packages/selenium/webdriver/chrome/webdriver.py”,第 70 行,在init super(WebDriver, self) 中。init(DesiredCapabilities.CHROME['browserName'],“goog”,檔案“/opt/python/lib/python3.8/site-packages/selenium/webdriver/chromium/webdriver.py”,第 90 行,在init self.service.start() 檔案“/opt/python/lib/python3.8/site-packages/selenium/webdriver/common/service.py”,第 98 行,在 start self.assert_process_still_running() 檔案“/opt/ python/lib/python3.8/site-packages/selenium/webdriver/common/service.py”,第 110 行,在 assert_process_still_running
注意:我的層結構在 zip 檔案的下方,并使用 curl 命令獲取 lambda 的 linux 驅動程式
curl -SL https://chromedriver.storage.googleapis.com/2.37/chromedriver_linux64.zip > chromedriver.zip
curl -SL https://github.com/adieuadieu/serverless-chrome/releases/download/v1.0.0-41/stable-headless-chromium-amazonlinux-2017-03.zip > headless-chromium.zip

uj5u.com熱心網友回復:
我使用了 python3.7 并使用了以下鏈接中提供的 zip 包
我的作業層
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/430359.html
標籤:Python 硒网络驱动程序 aws-lambda 硒铬驱动程序
上一篇:Pythonselenium:UnboundLocalError:分配前參考的區域變數“followin”
下一篇:在本教程中接收“TypeError:__init__()gotanunexpectedkeywordargument'basey'”
