长沙微信网站,钦州市住房和城乡建设局网站,网站推广原则,仿网站 涉及侵权吗有些定时任务需要使用自动化测试的工具#xff0c;如果使用亚马逊云科技 Lambda来实现这个功能的话#xff0c;那么就需要图形框架#xff0c;而我们知道lambda其实是一个虚拟机#xff0c;而且按照系统级别依赖比较困难。所以这里选择使用容器的形式进行发布。
在dockerf…有些定时任务需要使用自动化测试的工具如果使用亚马逊云科技 Lambda来实现这个功能的话那么就需要图形框架而我们知道lambda其实是一个虚拟机而且按照系统级别依赖比较困难。所以这里选择使用容器的形式进行发布。
在dockerfile中先安装chrome和对应的驱动然后再安装系统级别的依赖。 Dockerfile
FROM public.ecr.aws/lambda/pythonsha256:d8a8324834a079dbdfc6551831325113512a147bf70003622412565f216e36e0 as build
RUN yum install -y unzip \curl -Lo /tmp/chromedriver.zip https://chromedriver.storage.googleapis.com/114.0.5735.90/chromedriver_linux64.zip \curl -Lo /tmp/chrome-linux.zip https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/Linux_x64%2F1135561%2Fchrome-linux.zip?altmedia \unzip /tmp/chromedriver.zip -d /opt/ \unzip /tmp/chrome-linux.zip -d /opt/FROM public.ecr.aws/lambda/pythonsha256:d8a8324834a079dbdfc6551831325113512a147bf70003622412565f216e36e0
RUN yum install atk cups-libs gtk3 libXcomposite alsa-lib \libXcursor libXdamage libXext libXi libXrandr libXScrnSaver \libXtst pango at-spi2-atk libXt xorg-x11-server-Xvfb \xorg-x11-xauth dbus-glib dbus-glib-devel -y
RUN pip install selenium4.14.0
COPY --frombuild /opt/chrome-linux /opt/chrome
COPY --frombuild /opt/chromedriver /opt/
COPY main.py ./
CMD [ main.handler ]from selenium import webdriver
from tempfile import mkdtemp
from selenium.webdriver.common.by import Bydef handler(eventNone, contextNone):options webdriver.ChromeOptions()service webdriver.ChromeService(/opt/chromedriver)options.binary_location /opt/chrome/chromeoptions.add_argument(--headless)options.add_argument(--no-sandbox)options.add_argument(--disable-gpu)options.add_argument(--window-size1280x1696)options.add_argument(--single-process)options.add_argument(--disable-dev-shm-usage)options.add_argument(--disable-dev-tools)options.add_argument(--no-zygote)options.add_argument(f--user-data-dir{mkdtemp()})options.add_argument(f--data-path{mkdtemp()})options.add_argument(f--disk-cache-dir{mkdtemp()})options.add_argument(--remote-debugging-port9222)chrome webdriver.Chrome(optionsoptions, serviceservice)chrome.get(https://example.com/)return chrome.find_element(byBy.XPATH, value//html).text这个是项目地址 https://github.com/umihico/docker-selenium-lambda