忽然有个自动化需求因此准备使用模拟点击的方法,html
在使用以前的PhantomJS时,报错python
UserWarning: Selenium support for PhantomJS has been deprecated, please use headless versions of Chrome ……web
这时候的方法就是换到chrome了,若是你没装过,那么能够按照这里的方法去安装,若是已经安装了,也建议按照这里的方法去排查可能出现的问题,chrome
For Linuxapi
chromium-browser -version
sudo apt-get install chromium-browser
/usr/bin
directory sudo mv chromedriver /usr/bin
/usr/bin
directory cd /usr/bin
sudo chmod a+x chromedriver
to mark it executable.finally you can execute the code.app
from selenium import webdriver driver = webdriver.Chrome() driver.get("http://www.google.com") print driver.page_source.encode('utf-8') driver.quit() display.stop()
这样只会就应该能够用了,less
若是还报错,selenium.common.exceptions.WebDriverException: Message: '' executable may have wrong permissions.测试
那极有多是你没把执行路径添加到path,或者添加的路径不完整,全路径应该是包含chromedriver这个文件名的,不能只写到它所在的文件夹,ui
eg,google
chrome_path = '/usr/bin/chromedriver'
这样就能够了,下面是测试代码,正常执行的,
from selenium import webdriver from selenium.webdriver.chrome.options import Options chrome_options = Options() chrome_options.add_argument('--headless') chrome_options.add_argument('--disable-gpu') chrome_options.add_argument('--no-sandbox') chrome_options.add_argument('--disable-extensions') chrome_path = '/usr/bin/chromedriver' driver = webdriver.Chrome(executable_path=chrome_path, chrome_options=chrome_options) driver.get("https://cnblogs.com/")