下载整个网页?

Alo*_*lon 5 python urllib2 python-requests

当我在浏览器中右键单击页面时,我可以"将页面另存为",保存整个网页,包括图像,CSS和js.我已经看到有关下载页面内容的问题,但这只会检索HTML.urllib2,请求或任何其他库是否有下载整个页面的解决方案?

Yuu*_*Yuu 4

您可以使用pyautoguiCoupleselenium来实现此目的。

import time
from selenium import webdriver
import pyautogui

URL = 'https://example.com'

# open page with selenium
# (first need to download Chrome webdriver, or a firefox webdriver, etc)
driver = webdriver.Chrome()
driver.get(URL)

# open 'Save as...' to save html and assets
pyautogui.hotkey('ctrl', 's')
time.sleep(1)
pyautogui.typewrite('your_filename' + '.html')
pyautogui.hotkey('enter')
Run Code Online (Sandbox Code Playgroud)

参考