Ctrl + UCmd + Option + UF12 或右键选择“检查”。<html>)→ 选择 Copy → Copy outerHTML。.html 文件。Invoke-WebRequest -Uri "https://example.com" -OutFile "source.html"
curl -o source.html https://example.com
wget -O source.html https://example.com
import requests
url = "https://example.com" # 替换为目标URL
response = requests.get(url)
with open("source.html", "w", encoding="utf-8") as f:
f.write(response.text)
print("源码已保存为 source.html")
注意:

requests 库:pip install requests headers = {"User-Agent": "Mozilla/5.0 ..."}
response = requests.get(url, headers=headers)
安装扩展如 Save Page WE 或 SingleFile,一键保存完整网页(含资源)。
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://example.com")
with open("dynamic_source.html", "w") as f:
f.write(driver.page_source)
driver.quit()
./source.html 表示当前目录)。| 场景 | 推荐方法 |
|---|---|
| 快速查看源码 | 浏览器快捷键 Ctrl+U |
| 手动保存源码 | 右键复制 + 粘贴到编辑器 |
| 命令行批量下载 | curl / wget / PowerShell |
| 编程自动化 | Python requests / selenium |
| 保存完整网页(含资源) | 浏览器扩展(如 SingleFile) |
选择适合你的方式即可获取网页源码!

