1. 安装开发环境
安装 BeautifulSoup
安装 selenium
(1) 通过pip或者easy_intall 安装
命令:pip install BeautifulSoup
(2) 下载包安装
https://pypi.python.org/pypi/beautifulsoup4/4.3.2
http://www.seleniumhq.org/download/
推荐pip 安装
2. 下载
phantomjs-2.1.1-windows 和 chromedriver_win32(X64也用这个)
下载地址: http://pan.baidu.com/s/1gf7RfTh
下载后不用安装
3. 代码
#coding:utf-8
from selenium import webdriver
from time import sleep
from selenium import webdriver
from time import sleep
#这里设置用哪个,关于具体的使用可以百度,建议用phantomjs.exe读者可以做对比
# driver = webdriver.Chrome(r'D:\Python27\chromedriver.exe')
driver = webdriver.PhantomJS(r'D:\Python27\phantomjs-2.1.1-windows\phantomjs-2.1.1-windows\bin\phantomjs.exe')
driver.get("http://www.baidu.com")
# 找到百度的输入框,并输入“selenium”
driver.find_element_by_id('kw').send_keys('selenium')
sleep(2)
# 点击搜索按钮
driver.find_element_by_id('su').click()
#获取当前的URL的地址
print driver.current_url
#关闭浏览器
driver.close()
#PS:得到URL之后就可以用BS来做了