Selenium
Selenium is not just one tool or API but it composes many tools.
pip install -U selenium
Python安装Selenium
#!/usr/bin/python
# -*- coding:utf-8 -*-
from selenium import webdriver
if __name__ == "__main__":
driver = webdriver.Chrome() #webdriver提供访问、控制浏览器的API
driver.get("http://www.baidu.com/")
search_box = driver.find_element_by_id("kw")
search_box.send_keys("中华")
search_box.submit()
- 在运行程序之前,需要下载chromedriver,网址:
https://sites.google.com/a/chromium.org/chromedriver/downloads
- 在Windows环境下,将
chromedriver.exe
配置到PATH环境变量无效。
改将其放置代码引用文件同目录,有效。 - 另外,驱动程序的版本对chrome的版本有要求,最简单的方式,都升级到最新。