Chrome Lambda 函数中的驱动程序问题
Chrome Driver issue in Lambda function
我在 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)
错误:
[ERROR] WebDriverException: Message: Service /opt/chromedriver
unexpectedly exited. Status code was: 127
Traceback (most recent call last): File
"/var/task/lambda_function.py", line 27, in lambda_handler
driver = webdriver.Chrome('/opt/chromedriver', options=options) File
"/opt/python/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py",
line 70, in init
super(WebDriver, self).init(DesiredCapabilities.CHROME['browserName'], "goog",
File
"/opt/python/lib/python3.8/site-packages/selenium/webdriver/chromium/webdriver.py",
line 90, in init
self.service.start() File "/opt/python/lib/python3.8/site-packages/selenium/webdriver/common/service.py",
line 98, in start
self.assert_process_still_running() File "/opt/python/lib/python3.8/site-packages/selenium/webdriver/common/service.py",
line 110, in assert_process_still_running
注意: 我的层结构在 zip 文件中并使用 curl 命令获取 linux lambda 驱动程序
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
我使用了 python3.7 并使用了下面 link
中提供的 zip 包
我在 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)
错误:
[ERROR] WebDriverException: Message: Service /opt/chromedriver unexpectedly exited. Status code was: 127
Traceback (most recent call last): File "/var/task/lambda_function.py", line 27, in lambda_handler driver = webdriver.Chrome('/opt/chromedriver', options=options) File "/opt/python/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 70, in init super(WebDriver, self).init(DesiredCapabilities.CHROME['browserName'], "goog", File "/opt/python/lib/python3.8/site-packages/selenium/webdriver/chromium/webdriver.py", line 90, in init self.service.start() File "/opt/python/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 98, in start self.assert_process_still_running() File "/opt/python/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 110, in assert_process_still_running
注意: 我的层结构在 zip 文件中并使用 curl 命令获取 linux lambda 驱动程序
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
我使用了 python3.7 并使用了下面 link
中提供的 zip 包