使用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()