[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()

  

posted on 2018-11-16 17:26  张缤分  阅读(1823)  评论(0编辑  收藏  举报

导航