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. Mysql主从复制(重置版)

    MySQL Replication是Mysql自带的一种功能,可以实现将数据从一台数据库服务器(master)复制到一台或多台数据库服务器(slave),默认情况下属于异步复制,无需维持长连接.通过配 ...

  2. 123457123456---com.threeObj03.FanPaiZi01--- 记忆翻牌儿童

    com.threeObj03.FanPaiZi01--- 记忆翻牌儿童

  3. 设置滑动TabBar的显示和隐藏

    代码如下: //设置滑动的判定范围 - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint ...

  4. Page.ClientScript、ClientScript、ScriptManager、ClientScriptManager等的详细解说

    在 .aspx.cs页面中,输入这四个东西:Page.ClientScript.ClientScript.ScriptManager.ClientScriptManager,均会出提示,表示它们均可用 ...

  5. SSRS 2016 Forms Authentication

    SSRS 2016 comes with completely new report manager web interface and implementing form authenticatio ...

  6. canvas梦幻七彩泡泡

      <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&q ...

  7. word模板文档填充数据

    1.切记一定要用Word 97-2003(*.doc)格式的文档另存为 *.xml格式的文件,而不能用 Word 2007(*.docx)格式的word文档转 *.xml,将转成功之后的xml文件放入 ...

  8. 工作总结--CTO(张王岩)File的使用

    名称     路径分隔符 pathSeparator   separator 构造器 文件名.路径名 getName()  getPath() getAbsolutePath()  getParent ...

  9. IO-file-07 递归

    package com.bwie.io; /** * 递归: * 方法自己调用自己 * 递归头:何时结束递归 * 递归体:重复调用 * @author Allen17805272076 * */ pu ...

  10. [转帖]详解JVM内存布局及GC原理,值得收藏

    概述 https://www.toutiao.com/i6731345429574713868/ java发展历史上出现过很多垃圾回收器,各有各的适应场景,不仅仅是开发,作为运维也需要对这方面有一定的 ...