在Ubuntu(linux系统)上安装Firefox浏览器和geckodriver(无桌面)

1、下载并进入ubuntu镜像 

docker pull ubuntu
docker run -it --name py-selenium-firefox ubuntu bash
apt-get update

2、安装火狐浏览器

apt-get install firefox

3、查看浏览器版本


3、安装python及其依赖

apt-get install python3.6
apt-get install python3-pip
python3 -m pip install selenium

4、将github的上的geckodriver(https://github.com/mozilla/geckodriver/releases)下载下来,放到docker上面(docker cp命令)

tar -zxvf geckodriver-v0.26.0-linux64.tar.gz
mv geckodriver /usr/local/share/
ln -s /usr/local/share/geckodriver /usr/local/bin/geckodriver
ln -s /usr/local/share/geckodriver /usr/bin/geckodriver

5、将测试文件写好,放到docker上(test.py)

from selenium import webdriver

options = webdriver.FirefoxOptions()
options.add_argument('--headless')
driver = webdriver.Firefox(firefox_options=options)
driver.get('https://blog.csdn.net/u014595589/')
print(driver.title)
driver.close()

6、退出(exit)并生成镜像

docker commit py-selenium-firefox py-selenium-firefox

7、运行测试程序

docker run -it -e LANG=C.UTF-8 py-selenium-firefox python3 /home/test.py

镜像地址:

https://hub.docker.com/repository/docker/homealim2012/py-selenium-firefox

参考文献:

https://www.cnblogs.com/x54256/p/8403864.html

https://blog.csdn.net/lixianlin/article/details/80866598

你可能感兴趣的:(爬虫,ubuntu,docker,firefox,selenium,geckodriver)