多测师是一家拥有先进的教学理念,强大的师资团队,业内好评甚多的接口自动化测试培训机构!

17727591462

联系电话

您现在所在位置:接口自动化测试培训 > 新闻资讯

在Selenium中使用Ghostdriver抓取页面-自动化测试

更新时间:2022-04-22 09:30:25 作者:多测师 浏览:221

  安装ghostdriver

  因为ghostdriver已经和phantomjs合二为一了,所以直接安装phantomjs(phantomis就是一个基于webkit的无界面浏览器,浏览器能干的他大多能干,就是不渲染出最后的网页)

  直接下载phantomjs就好,由于各个平台的安装模式差异较大,就不多介绍了,百度一下就好。

在Selenium中使用Ghostdriver抓取页面-自动化测试

  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()

  以上内容为大家介绍了自动化测试中的在Selenium中使用Ghostdriver抓取页面,本文由多测师亲自撰写,希望对大家有所帮助。了解更多自动化测试相关知识:https://www.aichudan.com/xwzx/

联系电话

17727591462

返回顶部