截取屏幕:
# coding=utf-8
import getpass
from selenium import webdriver
import pyscreenshot as ImageGrab
#from Tkinter import Tk
import time
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument("--test-type")
driver = webdriver.Chrome(chrome_options=options)
driver.maximize_window()
def openurl(hostname, url):
driver.get(url)
#r = Tk()
hostname = hostname
time.sleep(2)
try:
im = ImageGrab.grab()
date = time.strftime("%Y-%m-%d %H.%M.%S")
im.save(hostname + "." + date + ".png")
# im.show()
# r.clipboard_clear()
except IOError:
pass
except AttributeError:
pass
if __name__ == "__main__":
# url1 = "http://10.136.1.74:80/DIplat/"
# url2 = ""
url1 = "https://cn.bing.com/"
urlall = {}
urlall["hostname1"] = url1
for hostname, url in urlall.items():
openurl(hostname, url)
截取网页屏幕:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument("--test-type")
#options.binary_location = "/usr/bin/chromium"
driver = webdriver.Chrome(chrome_options=options)
driver.get('https://***.com')
driver.find_element_by_id("idClose").click()
driver.save_screenshot("screenshot.png")
driver.close()