Skip to content

Instantly share code, notes, and snippets.

@ianchen06
Last active June 9, 2024 20:11
Show Gist options
  • Save ianchen06/26bf30c518a91351a7dab8a55924a6ab to your computer and use it in GitHub Desktop.
Save ianchen06/26bf30c518a91351a7dab8a55924a6ab to your computer and use it in GitHub Desktop.
undetected chrome driver in docker
import time
from pyvirtualdisplay import Display
import undetected_chromedriver as uc
disp = Display()
disp.start()
# display is active
chrome_options = uc.ChromeOptions()
chrome_options.add_argument("--no-sandbox")
#chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-gpu")
driver = uc.Chrome(headless=False,use_subprocess=False, options=chrome_options)
#driver.get('https://nowsecure.nl')
driver.get('https://www.dickssportinggoods.com/p/dsg-mens-9-stride-run-shorts-21qyfm9rnshrtxxxxdsg/21qyfm9rnshrtxxxxdsg?recid=home_PageElement_home3_rr_3_65281_&rrec=true')
time.sleep(10)
driver.save_screenshot('nowsecure.png')
disp.stop()
# display is stopped
FROM python:3.11-slim
WORKDIR /app
RUN apt-get update && apt-get install -y curl gnupg && curl -O https://packages.cloud.google.com/apt/doc/apt-key.gpg && apt-key add apt-key.gpg \
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
&& apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4EB27DB2A3B88B8B \
&& apt-get update \
&& apt-get install -y google-chrome-stable xvfb xserver-xephyr tigervnc-standalone-server x11-utils gnumeric
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
sudo docker build -t uc-crawler .
sudo docker run --shm-size 2g -it --rm -v $(pwd):/app uc-crawler bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment