add:https://stackoverflow.com/questions/22130109/cant-use-chrome-driver-for-selenium
For Linux 1. Check you have installed latest version of chrome brwoser-> "chromium-browser -version" 2. If not, install latest version of chrome "sudo apt-get install chromium-browser" 3. get appropriate version of chrome driver fromhttp://chromedriver.storage.googleapis.com/index.html 4. Unzip the chromedriver.zip 5. Move the file to /usr/bin directory sudo mv chromedriver /usr/bin 6. Goto /usr/bin directory and you would need to run something like "chmod a+x chromedriver" to mark it executable. 7. finally you can execute the code. import os from selenium import webdriver from pyvirtualdisplay import Display display = Display(visible=0, size=(800, 600)) display.start() driver = webdriver.Chrome() driver.get("http://www.google.com") print driver.page_source.encode('utf-8') driver.quit() display.stop()
[popexizhi]
pyvirtualdisplay 依赖 xvfb
pip install pyvirtualdisplay 前请sudo apt-get install xvfb
就可以直接使用了
|
没有评论:
发表评论