dimmg / dockselpy Goto Github PK
View Code? Open in Web Editor NEWDockerized Selenium and Python with support for Chrome, Firefox and PhantomJS
Dockerized Selenium and Python with support for Chrome, Firefox and PhantomJS
Several people have published this container to DockerHub but those forks have since diverged from this project and it would be really helpful to always have the canonical version of this project available on DockerHub instead.
Nice dockerfile, thanks! For anyone else, I got the following error after running the dockerfile and then executing docker exec <hash> python3 example.py
.
INFO:root:Initialized virtual display..
INFO:root:Prepared chrome options..
Traceback (most recent call last):
File "example.py", line 83, in <module>
chrome_example()
File "example.py", line 26, in chrome_example
browser = webdriver.Chrome()#chrome_options=chrome_options)
File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/chrome/webdriver.py", line 75, in __init__
desired_capabilities=desired_capabilities)
File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/remote/webdriver.py", line 156, in __init__
self.start_session(capabilities, browser_profile)
File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/remote/webdriver.py", line 251, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/remote/webdriver.py", line 318, in execute
response = self.command_executor.execute(driver_command, params)
File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/remote/remote_connection.py", line 375, in execute
return self._request(command_info[0], url, body=data)
File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/remote/remote_connection.py", line 397, in _request
resp = self._conn.request(method, url, body=body, headers=headers)
File "/usr/lib/python3/dist-packages/urllib3/request.py", line 79, in request
**urlopen_kw)
File "/usr/lib/python3/dist-packages/urllib3/request.py", line 142, in request_encode_body
**urlopen_kw)
TypeError: urlopen() got multiple values for keyword argument 'body'
This is because I had version 1.7.1 of urllib3 installed in the image (I'm guessing this is the latest one in the repository. See this stackoverflow link
I fixed this issue by adding the following line RUN pip3 install urllib3 --upgrade
to line 48 of the dockerfile. Pip complains about system packages but does install the correct one (you can check by adding RUN python3 -c "import urllib3; print(urllib3.__version__)"
to the last line of the docker file)
I think we should add more type of browser like Edge and Safari. I realize there will be a drawback in the size of the image. But it can be solved by telling the developer to comment unused browser in Dockerfile
.
So I got this problem when I want to use Firefox as the driver. This problem has ever been asked in here in Stackoverflow and I think the problem is because mismatch version between Firefox and Geckodriver. I think we can't use latest version in Firefox installation.
I think you should write in README.md
that selenium==3.141.0
and do versioning in python like sudo apt -y install python3.8
Hello, I am getting the build error No matching distribution found for libu2f-udev
How would I add libu2f-udev
?
I have left comments with what I tried below.
FROM ubuntu.jammy:latest
## note tried focal as well... didn't work
ARG DEBIAN_FRONTEND=noninteractive
RUN echo "===> Installing system dependencies..." && \
BUILD_DEPS="curl unzip" && \
apt-get update && apt-get install --no-install-recommends -y \
python3 python3-pip wget \
fonts-liberation libappindicator3-1 libasound2 libatk-bridge2.0-0 \
## adding libu2f-udev after libvulkan1 did not work...
libnspr4 libnss3 lsb-release xdg-utils libxss1 libdbus-glib-1-2 libgbm1 libvulkan1 \
$BUILD_DEPS \
xvfb
## does not work..
RUN wget http://archive.ubuntu.com/ubuntu/pool/main/libu/libu2f-host/libu2f-udev_1.1.4-1_all.deb && \
dpkg -i libu2f-udev_1.1.4-1_all.deb
## also does not work
# RUN apt-get install equivs -y && \
# equivs-control libu2f-udev && \
# equivs-build libu2f-udev && \
# dpkg -i libu2f-udev_1.0_all.deb
RUN echo "===> Installing chromedriver and google-chrome..." && \
CHROMEDRIVER_VERSION=`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE` && \
wget https://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip && \
unzip chromedriver_linux64.zip -d /usr/bin && \
chmod +x /usr/bin/chromedriver && \
rm chromedriver_linux64.zip && \
\
CHROME_SETUP=google-chrome.deb && \
wget -O $CHROME_SETUP "https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb" && \
dpkg -i $CHROME_SETUP && \
apt-get install -y -f && \
rm $CHROME_SETUP
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8
ENV PCD_FILE pcd_file
ENV PYTHONUNBUFFERED=1
ENV APP_HOME /usr/src/app
WORKDIR /$APP_HOME
COPY . $APP_HOME/
RUN pip3 install --trusted-host pypi.python.org -r $APP_HOME/requirements.txt
CMD tail -f /dev/null
CMD python3 mscript.py
Hi Dim! Why do you think I can't connect using proxies?
def selenium_connect():
PROXY = "66.97.38.58:80"
url = "http://whatsmyip.org"
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--proxy-server=%s' % PROXY)
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get(url)
Been struggling with these and can't seem to find a way.
There is an issue when trying to fetch the GECKODRIVER_VERSION, the command returns a non-zero code (1).
I found a simple fix if you're having this issue, you just have to edit the command into this: curl -i https://github.com/mozilla/geckodriver/releases/latest | grep -Po 'v[0-9]+.[0-9]+.[0-9]+'
and it works perfectly.
I'll create a P/R that includes this fix.
Hi there,
When I run the command:
docker build -t selenium_docker .
In the phase of installing google-chrome-stable, I got the following issue:
Unpacking google-chrome-stable (89.0.4389.82-1) ...
dpkg: dependency problems prevent configuration of google-chrome-stable:
google-chrome-stable depends on libgbm1 (>= 8.1~0); however:
Package libgbm1 is not installed.
dpkg: error processing package google-chrome-stable (--install):
dependency problems - leaving unconfigured
I guess that the base environment is missing libgbm1
library then I updated the Dockerfile to prior of google-chrome-stable step:
RUN apt-get update & apt-get install -y libgbm1
Then try again and I am able to build the new image as expected.
Environment: MacOS
Please contact me if you have any questions!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.