Giter Site home page Giter Site logo

alpine-selenium-chrome's Introduction

说明

Alpine:v3.4 + Selenium + Chrome

创建镜像

$ docker build -t="leafney/alpine-selenium-chrome" .

创建一个容器进行测试

$ docker run -it --name alsech leafney/alpine-selenium-chrome /bin/sh

拷贝py程序到容器中

$ docker cp chrome.py alsech:/root

Size

leafney/alpine-selenium-chrome latest 272.8 MB


Selenium + Chrome Demo

chrome.py

# coding:utf-8
import time
from selenium import webdriver
from pyvirtualdisplay import Display

display = Display(visible=0, size=(800, 800))
display.start()

driver = webdriver.Chrome()

driver.get('http://www.cnblogs.com/')
time.sleep(5)

title = driver.title
print(title.encode('utf-8'))

# html=driver.page_source
# print(html)

# Release memory
driver.close()
driver.quit()
display.stop()

Something Important

If you run the chrome.py file has error:

Message: unknown error: Chrome failed to start: crashed

And run chromium-browser has following error:

# chromium-browser
Failed to move to new namespace: PID namespaces supported, Network namespace supported, but failed: errno = Operation not permitted

Then to use the following method to solved it:

chrome_fix.py

# coding:utf-8
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from pyvirtualdisplay import Display

display = Display(visible=0, size=(800, 800))
display.start()

chrome_options = Options()
chrome_options.add_argument("--no-sandbox")
driver = webdriver.Chrome(chrome_options=chrome_options)

driver.get('http://www.cnblogs.com/')
time.sleep(5)

title = driver.title
print(title.encode('utf-8'))

# html=driver.page_source
# print(html)

# Release memory
driver.close()
driver.quit()
display.stop()

Details view: google-chrome fails to start in docker

alpine-selenium-chrome's People

Contributors

leafney avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.