phantomjs是一款软件,需要重新安装。

参考:

https://blog.csdn.net/liyahui_3163/article/details/79064108

案例代码:

from selenium import webdriver
import time
from PIL import Image driver = webdriver.PhantomJS(r"D:\zzl\biancheng\phantomjs-2.1.1-windows\bin\phantomjs.exe")
driver.get('https://www.baidu.com/')
time.sleep(3) # 演示一:全网页截图
# driver.save_screenshot('screenshot.png')
# driver.quit() # 演示二:定位区块截图
driver.save_screenshot(r'photo.png') # 一次截图:形成全图
baidu = driver.find_element_by_id('su') # 截图按钮百度一下
# baidu = driver.find_element_by_xpath("//div[@id='lg']/img[@class='index-logo-src']") #截图百度logo图片
# print(baidu)
left = baidu.location['x'] # 区块截图左上角在网页中的x坐标
top = baidu.location['y'] # 区块截图左上角在网页中的y坐标
right = left + baidu.size['width'] # 区块截图右下角在网页中的x坐标
bottom = top + baidu.size['height'] # 区块截图右下角在网页中的y坐标
# print({"left": left, "top": top, "right": right, "bottom ": bottom})
# print("baidu.size['width']:%s" % baidu.size['width'])
# print("baidu.size['height']:%s" % baidu.size['height'])
picture = Image.open(r'photo.png')
picture = picture.crop((left, top, right, bottom)) # 二次截图:形成区块截图
picture.save(r'photo2.png')
driver.quit()

  

延伸:

phantomjs出bug的解决方法:(截图找bug)

driver = webdriver.PhantomJS()
driver.set_window_size(1920,1080)
try:
driver.get('http://whatsmyuseragent.com/') except Exception,e:
driver.save_screenshot('screenshot.png') driver.close()

  

selenium网页截图和截图定位(无界面)phantomjs的更多相关文章

  1. selenium2支持无界面操作(HtmlUnit和PhantomJs)

    selenium2支持无界面操作(HtmlUnit和PhantomJs) selenium2支持通过各种driver(FirfoxDriver,IternetExplorerDriver,OperaD ...

  2. python selenium chrome有界面与无界面模式

    from selenium.webdriver.chrome.options import Options from selenium import webdriver # 无界面模式 def Chr ...

  3. ubuntu中如何安装selenium+chrome(headless)无界面浏览器?

    selenium是一个Web的自动化测试工具,它可以根据我们的指令,让浏览器自动加载页面,获取需要的数据,甚至页面截屏,或者判断网站上某些动作是否发生.但是它自身不带浏览器,不支持浏览器的功能,因此它 ...

  4. selenium web driver 实现截图功能

    在验证某些关键步骤时,需要截个图来记录一下当时的情况 Webdriver截图时,需要引入 import java.io.File; import java.io.IOException; import ...

  5. selenium(六)Headless Chrome/Firefox--PhantomJS停止支持后,使用无界面模式。

    简介: 以前都用PhantomJS来进行无界面模式的自动化测试,或者爬取某些动态页面. 但是最近selenium更新以后,'Selenium support for PhantomJS has bee ...

  6. selenium无界面chromedriver

    chromeDriver下载地址:http://chromedriver.storage.googleapis.com/index.html 谷歌浏览器Chrome和驱动程序的对照表https://b ...

  7. XVFB实现selenium在linux上无界面运行安装篇

    selenium在linux上无界面运行,其实是非常简单的.具体的方法有使用HtmlUnitDriver或者PhantomJSDriver,有时间我会写写关于这两个东东的文章,其实基本和ChromeD ...

  8. selenium phantomjs java无界面浏览器环境搭建

    java selenium搭建无界面浏览器 1.http://phantomjs.org/ 下载windows版phantomjs 2.解压后bin目录下会有exe文件 3.测试代码: package ...

  9. selenium无界面执行和反爬

    selenium无界面执行和反爬 无界面执行 from selenium import webdriver from selenium.webdriver.chrome.options import ...

随机推荐

  1. hadoop目录命令

    下面是经常使用到的,以此记录备忘 1.查看hadoop目录 命令: hadoop fs -ls / 2.创建目录 命令:hadoop fs -mkdir /目录名 3.将文件上传hadoop中(也就是 ...

  2. socket 一个websocke对应一个socketclient对象

    using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Co ...

  3. mybatis传入map任意表增删改查,分页过滤字段

    <!--根据实体参数查询 --> <select id="selectBaseList" resultType="java.util.HashMap&q ...

  4. pycharm操作Django基础部分

    原文地址:https://www.cnblogs.com/feixuelove1009/p/5823135.html

  5. Selenium ? 也要学...!

    一.selenium 简介 Selenium是ThroughtWorks公司一个强大的开源Web功能测试工具系列,包括Selenium-IDE.Selenium-RC.Selenium-Webdriv ...

  6. 印象笔记·剪藏 Chrome插件

    印象笔记·剪藏 Chrome插件 链接:https://pan.baidu.com/s/10nzrSk_3sLkOI29MIEPEBw  密码:p8n8

  7. Opencv官方例程简介

    opencv sample文件夹例程 No1. adaptiveskindetector.cpp 利用HSV空间的色调信息的皮肤检测,背景不能有太多与肤色相似的颜色.效果不是特别好. No2. bag ...

  8. 最新 翔通动漫java校招面经 (含整理过的面试题大全)

    从6月到10月,经过4个月努力和坚持,自己有幸拿到了网易雷火.京东.去哪儿.翔通动漫等10家互联网公司的校招Offer,因为某些自身原因最终选择了翔通动漫.6.7月主要是做系统复习.项目复盘.Leet ...

  9. tomcat性能优化参数

    线上环境使用默认tomcat配置文件,性能很一般,为了满足大量用户的访问,需要对tomcat进行参数性能优化,具体优化的地方如下: Linux内核的优化 服务器资源JVM 配置的优化 Tomcat参数 ...

  10. Oracle日常

    Xmltype select extractvalue(value(x), '//utext') value from table(XMLSEQUENCE(extract(v_xmlContent, ...