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. python 运算符和小数据池

    计算机可以进行的运算有很多种,可不只加减乘除这么简单,运算按种类可分为算数运算.比较运算.逻辑运算.赋值运算.成员运算.身份运算.位运算,今天我们暂只学习算数运算.比较运算.逻辑运算.赋值运算 算数运 ...

  2. LD_LIBRARY_PATH无效

    在os x 上设置LD_LIBRARY_PATH无效,env命令看不到这个变量,下面的文章说明了这个问题 说明:网上基本针对这个值的设置分为两面,Windows派和Linux派,Windows的不说, ...

  3. sql的游标用法举例(Cursor)

    sql的游标用法举例 ), ) Declare authors_cursor Cursor For Select Name,TrueName From Account Open authors_cur ...

  4. Python3之使用枚举类

    当我们需要定义常量时,一个方法是用大写变量通过整数来定义,例如月份 JAN = 1 FEB = 2 MAR = 3 APR=4 May=5 Jun=6 Jul=7 Aug=8 Sep=9 Oct=10 ...

  5. 记录git 软件库

    https://github.com/phpredis/phpredis   redis扩展 https://github.com/tecnickcom/tcpdf 生成PDF 后续......

  6. execl文件读取封装

    前言:做自动化常用的公共方法 注:第一次使用记得先 pip install xlrd 模块import xlrd class ReadExecl(): def __init__(self,filena ...

  7. C#基础知识学习 三

  8. 1.Cloudera Manager安装

    安装环境采用2台虚拟机进行,一台master, 一台slave1 先安装好centos 6.5 两台,并设置静态ip 怎么安装可以参考地址:https://jingyan.baidu.com/arti ...

  9. 【51nod】1776 路径计数

    [51nod]1776 路径计数 我们先把前两种数给排好,排好之后会有\(a + b + 1\)个空隙可以填数,我们计算有\(k\)个空隙两端都是相同字母的方案数 可以用枚举把第二种数分成几段插进去来 ...

  10. python第一个浏览器的自动执行程序

    1.目标:简单点,百度搜索“美丽的程序员” 2.操作方法: a.python已经安装完成 b.安装PIP:在windows的cmd窗口下输入easy_install pip      c.安装sele ...