# -*- coding:utf-8 -*-
from selenium import webdriver
import win32api
import win32con
import win32gui
import win32clipboard
from ctypes import *
import time
import os
def save_html(url):
browser = webdriver.Chrome()
browser.get(url)
time.sleep(2)
title = browser.title
path = "E:\pic" + "\\" + title + ".html"
print(path)
# 按下ctrl+s
win32api.keybd_event(0x11, 0, 0, 0)
win32api.keybd_event(0x53, 0, 0, 0)
win32api.keybd_event(0x53, 0, win32con.KEYEVENTF_KEYUP, 0)
win32api.keybd_event(0x11, 0, win32con.KEYEVENTF_KEYUP, 0)
time.sleep(1)
classname = u"#32770"
titlename = u"另存为"
hwnd = win32gui.FindWindow(classname,titlename)
win32gui.ShowWindow(hwnd, win32con.SW_SHOWNORMAL)
a1 = win32gui.FindWindowEx(hwnd,None,"DUIViewWndClassName",None)
a2 = win32gui.FindWindowEx(a1,None,"DirectUIHWND",None)
a3 = win32gui.FindWindowEx(a2,None,"FloatNotifySink",None)
a4 = win32gui.FindWindowEx(a3,None,"ComboBox",None)
hwnd_filepath = win32gui.FindWindowEx(a4,None,"Edit",None)
win32gui.SendMessage(hwnd_filepath, win32con.WM_SETTEXT, None, path)
# #按下回车
win32api.keybd_event(0x0D,0,0,0)
win32api.keybd_event(0x0D,0,win32con.KEYEVENTF_KEYUP,0)
time.sleep(1)
win32api.keybd_event(0x0D,0,0,0)
win32api.keybd_event(0x0D,0,win32con.KEYEVENTF_KEYUP,0)
time.sleep(7)#下载需要时间
browser.close()
将谷歌浏览器网页另存为html
最新推荐文章于 2021-06-04 08:41:45 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)