Python使用Selenium/PhantomJS
安装selenium:
1
|
pip install selenium |
安装PhantomJS:
1
2
3
4
|
https: //bitbucket .org /ariya/phantomjs/downloads/phantomjs-1 .9.7-linux-x86_64. tar .bz2 tar jxvf phantomjs-1.9.7-linux-x86_64. tar .bz2 cp phantomjs-1.9.7-linux-x86_64 /bin/phantomjs /bin/ chmod 755 /bin/phantomjs |
使用示例:
1
2
3
4
5
|
from selenium import webdriver driver = webdriver.PhantomJS() driver.get( "http://www.baidu.com" ) data = driver.title print data |
通过Remote Selenium Server:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
from selenium import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCapabilities driver = webdriver.Remote( command_executor = 'http://192.168.1.3:4444/wd/hub' , desired_capabilities = { 'browserName' : 'PhantomJS' , 'version' : '2' , 'javascriptEnabled' : True }) driver = webdriver.Remote( command_executor = 'http://192.168.1.3:4444/wd/hub' , desired_capabilities = DesiredCapabilities.PHANTOMJS) driver.get( "http://www.baidu.com" ) data = driver.title print data |
PhantomJS和Firefox速度对比:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
import unittest from selenium import webdriver import time class TestThree(unittest.TestCase): def setUp( self ): self .startTime = time.time() def test_url_fire( self ): self .driver = webdriver.Firefox() self .driver.get( "http://www.qq.com" ) self .driver.quit() def test_url_phantom( self ): self .driver = webdriver.PhantomJS() self .driver.get( "http://www.qq.com" ) self .driver.quit() def tearDown( self ): t = time.time() - self .startTime print "%s: %.3f" % ( self . id (), t) self .driver.quit if __name__ = = '__main__' : suite = unittest.TestLoader().loadTestsFromTestCase(TestThree) unittest.TextTestRunner(verbosity = 0 ).run(suite) |
Python使用Selenium/PhantomJS的更多相关文章
- [Python爬虫] Selenium+Phantomjs动态获取CSDN下载资源信息和评论
前面几篇文章介绍了Selenium.PhantomJS的基础知识及安装过程,这篇文章是一篇应用.通过Selenium调用Phantomjs获取CSDN下载资源的信息,最重要的是动态获取资源的评论,它是 ...
- Python 之selenium+phantomJS斗鱼抓取案例
from selenium import webdriver from bs4 import BeautifulSoup import time if __name__ == '__main__': ...
- [Python爬虫] Selenium +phantomjs 模拟下拉滚动条
在爬虫中,有时会遇到这种情况,数据的展示是不是一页一页的,而是通过不断的下拉滚动条来加载数据.例如一点咨询(http://www.yidianzixun.com/)和微博(在未登录的状态下:http: ...
- [python爬虫] Selenium常见元素定位方法和操作的学习介绍
这篇文章主要Selenium+Python自动测试或爬虫中的常见定位方法.鼠标操作.键盘操作介绍,希望该篇基础性文章对你有所帮助,如果有错误或不足之处,请海涵~同时CSDN总是屏蔽这篇文章,再加上最近 ...
- Selenium + PhantomJS + python 简单实现爬虫的功能
Selenium 一.简介 selenium是一个用于Web应用自动化程序测试的工具,测试直接运行在浏览器中,就像真正的用户在操作一样 selenium2支持通过驱动真实浏览器(FirfoxDrive ...
- Python爬虫使用Selenium+PhantomJS抓取Ajax和动态HTML内容
1,引言 在Python网络爬虫内容提取器一文我们详细讲解了核心部件:可插拔的内容提取器类gsExtractor.本文记录了确定gsExtractor的技术路线过程中所做的编程实验.这是第二部分,第一 ...
- python selenium+phantomjs alert()弹窗报错
问题:用selenium+phantomjs 模拟登陆,网页用JavaScript的alert("登陆成功")弹出框,但是用switch_to_alert().accept()报错 ...
- python+selenium+PhantomJS爬取网页动态加载内容
一般我们使用python的第三方库requests及框架scrapy来爬取网上的资源,但是设计javascript渲染的页面却不能抓取,此时,我们使用web自动化测试化工具Selenium+无界面浏览 ...
- python+selenium+PhantomJS批量投递智联简历(不要用自己的账号进行测试,请使用小号,很烦人的,哈哈哈)
1.环境python2.7+selenium+PhantomJS(软件安装和库的安装网上都有教程我们跳过,so easy) 2.原理 绕过首页登录需要验证码,直接进入搜索栏,输入搜索的职位+地区搜索出 ...
随机推荐
- 利用htmlunit登陆带验证码图片的网站
http://htsoft.org/html/y2011/822_using-htmlunit-landing-site-with-captcha-image.html 利用htmlunit登陆带验证 ...
- 编程实现prim算法和Dijkstra算法。
网址链接:http://blog.csdn.net/anialy/article/details/7603170
- linux文件分割(将大的日志文件分割成小的)【转载】
linux文件分割(将大的日志文件分割成小的)linux下文件分割可以通过split命令来实现,可以指定按行数分割和安大小分割两种模式.Linux下文件合并可以通过cat命令来实现,非常简单. 在Li ...
- linux export将PATH环境变量误删了的解决办法
今天新增环境变量的时候不小心把冒号错打成了分号 export PATH=/usr/local/php5/bin;$PATH; 导致PATH变量为/usr/local/php/bin 解决办法:[ubu ...
- sql视图
什么是视图 大家都知道,我们国家现在“神七”上天了.从美国的月球登月开始,人类上天不再是神话.听说,在美国,你只要出几十万美元,您就可以上一次月球进行太空旅行,所以,我们相信:在不久的将来,上天旅行将 ...
- USB的八个问题和答案(转)
http://www.amobbs.com/thread-901041-1-1.html 问题一:USB的传输线结构是如何的呢? 答案一:一条USB的传输线分别由地线.电源线.D+.D-四条线构成,D ...
- zf-关于分页的行数如何配置
公司的项目分页显示行数是在web.xml里配置的 对应的java 文件是 BaseAction 这个文件里面写的就是分页的代码
- zf-关于注册码全部错误的解决方法
之所以错误,是因为这里的用户名称是石首市政务服务中心. 在数据库里把这个字段改成 上海卓繁 就可以了 一般都是在 SYS_INFO 这张表里面改
- 转 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
软件开发的一般流程为工程师开发 -> 测试 -> 上线,因此就涉及到三个不同的环境,开发环境.测试环境以及生产环境,通常 ...
- FusionCharts使用问题及解决方法(四)-FusionCharts常见问题大全
在前3篇文章中,我们总结了FusionCharts图表的一些常见问题(FAQ)及解决方法,本文继续讨论FusionCharts使用者常见的一些复杂的报错及解决方法. 问题描述:使用FusionChar ...