zoukankan      html  css  js  c++  java
  • 使用chromedriver实现豆瓣网页的全网页截图

        最近由于工作需要,需要对部分网站进行全文截屏。在网上搜了很久没有搜出好的方法,而且在新版的selenium中已经不在支持PhantomJS了,所以全文截取变得有点棘手。

        此处给出一个简单的方法,以20行代码实现selenium+chromedriver+python实现豆瓣的全文截取。

    from selenium import webdriver
    
    options = webdriver.ChromeOptions()
    options.add_argument('--headless')
    options.add_argument('--dns-prefetch-disable')
    options.add_argument('--no-referrers')
    options.add_argument('--disable-gpu')
    options.add_argument('--disable-audio')
    options.add_argument('--no-sandbox')
    options.add_argument('--ignore-certificate-errors')
    options.add_argument('--allow-insecure-localhost')
    
    driver = webdriver.Chrome(options=options)
    driver.get('http://www.douban.com')
    width = driver.execute_script(
            "return Math.max(document.body.scrollWidth, document.body.offsetWidth, document.documentElement.clientWidth, document.documentElement.scrollWidth, document.documentElement.offsetWidth);")
    height = driver.execute_script(
            "return Math.max(document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight);")
    driver.set_window_size(width + 100, height + 100)
    driver.save_screenshot('douban.png')
    driver.close()

    以下为截屏效果:

  • 相关阅读:
    VC CUtilityLZW 效率还行的LZW压缩算法,随机数加密
    VC CQHashNTBuffer 牛逼的Hash表 UINT32
    VC CHashBuffer 牛逼的hash表算法,字符串查找块了100倍
    关闭Fedora防火墙
    gnome 屏幕截图
    zynq -- arm-xilinx-eabi-路径
    Fedora 14安装出现的错误
    fedora19安装后,需要安装的一些必备的软件包
    zynq -- cannot find -lxil
    Zynq -- 启动过程
  • 原文地址:https://www.cnblogs.com/zhy128/p/10237130.html
Copyright © 2011-2022 走看看