标签:question bindings nbsp ali mono cal ant pretty linu
突然有个自动化需求所以准备使用模拟点击的方法,
在使用之前的PhantomJS时,报错
UserWarning: Selenium support for PhantomJS has been deprecated, please use headless versions of Chrome ……
这时候的方法就是换到chrome了,如果你没装过,那么可以按照这里的方法去安装,如果已经安装了,也建议按照这里的方法去排查可能出现的问题,
For Linux
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.
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("http://www.google.com")
print driver.page_source.encode(‘utf-8‘)
driver.quit()
display.stop()
这样只会就应该可以用了,
如果还报错,selenium.common.exceptions.WebDriverException: Message: ‘‘ executable may have wrong permissions.
那极有可能是你没把执行路径添加到path,或者添加的路径不完整,全路径应该是包含chromedriver这个文件名的,不能只写到它所在的文件夹,
eg,
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/")
centos7上PhantomJS 过期之后改用Chrome时填的坑
标签:question bindings nbsp ali mono cal ant pretty linu
原文地址:https://www.cnblogs.com/1394htw/p/10309390.html