[Chrome Headless + Python] 截长图 (Take Full-page Screenshot)

# -*- coding: utf-8 -*-
import time
import os

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

jenkinsJobName=os.getenv("JOB_NAME")
url="http://*.*.*.*/test.html"
print url
save_fn="testResult.PNG"

option = webdriver.ChromeOptions()
option.add_argument(\'--headless\')
option.add_argument(\'--disable-gpu\')
option.add_argument("--window-size=1280,1024")
option.add_argument("--hide-scrollbars")

driver = webdriver.Chrome(chrome_options=option)

driver.get(url)
print(driver.title)

scroll_width = driver.execute_script(\'return document.body.parentNode.scrollWidth\')
scroll_height = driver.execute_script(\'return document.body.parentNode.scrollHeight\')
driver.set_window_size(scroll_width, scroll_height)
driver.save_screenshot(save_fn)
driver.quit()

  

版权声明:本文为MasterMonkInTemple原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/MasterMonkInTemple/p/9970512.html