在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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章