https://github.com/leafney/alpine-selenium-chrome
Alpine:v3.4 + Selenium + Chrome
https://github.com/leafney/alpine-selenium-chrome
Last synced: 3 months ago
JSON representation
Alpine:v3.4 + Selenium + Chrome
- Host: GitHub
- URL: https://github.com/leafney/alpine-selenium-chrome
- Owner: leafney
- Created: 2016-10-23T11:57:46.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-11-09T07:05:08.000Z (over 7 years ago)
- Last Synced: 2025-01-14T15:23:47.251Z (5 months ago)
- Size: 1000 Bytes
- Stars: 12
- Watchers: 2
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
#### 说明
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 Displaydisplay = 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 Displaydisplay = 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](https://github.com/wechaty/wechaty/issues/26)