爬虫利器:Selenium+PhantomJS
2016-10-20 21:07
471 查看
Selenium
Selenium是一个可以真实模拟浏览器运作的工具。需要下载selenium.exe文件和安装
selenium包。
下面是一个简单的模拟访问百度,并点击进入python官网的例子。
# coding=utf-8 from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC driver = webdriver.Chrome() driver.get("http://www.baidu.com") assert u"百度一下" in driver.title elem = driver.find_element_by_xpath("//*[@id=\"kw\"]") elem.clear() elem.send_keys("python") elem.send_keys(Keys.RETURN) WebDriverWait(driver,10).until( EC.presence_of_all_elements_located((By.LINK_TEXT,'Welcome to Python.org')) ) driver.find_element_by_link_text("Welcome to Python.org").click()
需要注意的是这里显示的等待了,百度搜索页面加载完毕。
官方文档
PhantomJS
这是一个没有界面的浏览器,对js的加载行为完全一样,因为启动Chrome比较慢,所以通过这个可以比较快的完成!一般来说就是先用Chrome可视化的加载,等待完成以后,改变浏览器的引擎就可以了!driver = webdriver.PhantomJS()
这样配置就可以使用了!
相关文章推荐
- Python爬虫利器Selenium+PhantomJS系列入门
- 入手爬虫利器:phantomjs+selenium、自动填充文本框、自动点按钮
- Java之网络爬虫WebCollector+selenium+phantomjs(二)
- Scrapy+PhantomJS+Selenium动态爬虫
- [Python爬虫] 在Windows下安装PIP+Phantomjs+Selenium
- python爬虫(17)爬出新高度_抓取微信公众号文章(selenium+phantomjs)(上)
- Python爬虫学习——使用selenium和phantomjs爬取js动态加载的网页
- 爬虫入门五(Phantomjs和selenium)
- Python爬虫使用Selenium+PhantomJS抓取Ajax和动态HTML内容
- Java之网络爬虫WebCollector+selenium+phantomjs(三)
- python3.6+selenium+phantomJS 网页爬虫报错NoSuchElementException问题及解决方法
- Python爬虫——5-2.使用selenium和phantomjs模拟QQ空间登录
- Python爬虫利器五之Selenium的用法
- [Python爬虫] 之二十七:Selenium +phantomjs 利用 pyquery抓取今日头条视频
- linux爬虫开发环境配置python+selenium+phantomJS
- python爬虫之 selenium + phantomjs 爬斗鱼所有直播间
- selenium配合phantomjs实现爬虫功能,并把抓取的数据写入excel
- 直播网站LiveTV Mining,爬虫抓取数据 python3+selenium+phantomjs
- Python爬虫使用Selenium+PhantomJS抓取Ajax和动态HTML内容
- [Python爬虫] 之二十二:Selenium +phantomjs 利用 pyquery抓取界面网站数据