在Selenium中使用Ghostdriver抓取页面

发表于:2016-6-28 11:04

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:明慢慢    来源:51Testing软件测试网采编

  缘起
  一位firefox抓取速度慢,想加速,发现通过无界面的浏览器取抓取就可以快很多,因为不用进行浏览器页面渲染,这个可是非常耗费时间的。这个理由够了把。
  安装ghostdriver
  因为ghostdriver已经和phantomjs合二为一了,所以直接安装phantomjs(phantomis就是一个基于webkit的无界面浏览器,浏览器能干的他大多能干,就是不渲染出最后的网页)
  直接下载phantomjs就好,由于各个平台的安装模式差异较大,就不多介绍了,百度一把就好。
  linux or mac 备忘一句
#mac拥护请在地址下载,否则出错kill:9
#https://github.com/eugene1g/phantomjs/releases
#软链接phantomjs
ln -s /where/dir/phantomjs  /usr/local/bin/phantomjs
  python 测试
#coding=utf-8
from selenium import webdriver
import time
import os
br=webdriver.PhantomJS('phantomjs')
baseurl="http://quote.eastmoney.com/"
indexurl="stocklist.html"
gourl="%s%s"%(baseurl,indexurl)
br.get(gourl)
print br.title
time.sleep(5)
br.quit()
  phantomjs 截图
#coding=utf-8
from selenium import webdriver
import time
import os
br=webdriver.PhantomJS('phantomjs')
baseurl="http://quote.eastmoney.com/"
indexurl="stocklist.html"
gourl="%s%s"%(baseurl,indexurl)
br.get(gourl)
br.save_screenshot('./股票列表.png')
print "完成"
br.quit()
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号