悠悠的博客

每日一记,记录学习

使用selenium时遇到WebDriverException

使用selenium时遇到:
WebDriverException: 'chromedriver' executable needs to be in PATH. 
Please see https://sites.google.com/a/chromium.org/chromedriver/home

使用谷歌浏览器,下载最新版的chromedriver,
http://chromedriver.storage.googleapis.com/index.html
将解压后的文件复制至python的安装目录下;

chromedriver需与谷歌浏览器版本对应;
在谷歌浏览器版菜单的帮助子菜单下的关于chrome查看更新浏览器。


from selenium import webdriver
import time

# path=r"D:\Program Files (x86)\phantomjs-2.1.1-windows\bin\phantomjs.exe"
#
# driver = webdriver.PhantomJS(executable_path=path)
# driver.get("http://pythonscraping.com/pages/javascript/ajaxDemo.html")
# time.sleep(3)
# print(driver.find_element_by_id('content').text)
# driver.close()

from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get("http://pythonscraping.com/pages/javascript/ajaxDemo.html")
time.sleep(3)
print(driver.find_element_by_id('content').text)
driver.close()

            
阅读更多
个人分类: python
上一篇django模型内部类meta详细解释
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭