要下载整个网页的HTML,可以使用Python的 requests 库发送HTTP请求,然后将响应内容作为Beautiful Soup的输入。以下是一个示例代码:
import requests
from bs4 import BeautifulSoup
url = "https://example.com" # 要下载HTML的网页URL
# 发送HTTP GET请求获取网页内容
response = requests.get(url)
html = response.text
# 使用Beautiful Soup解析HTML
soup = BeautifulSoup(html, "html.parser")
# 打印页面的标题
title = soup.title
print("页面标题:", title.string)
请注意,示例代码中的"https://example.com"仅为示例网址,你需要替换为你想下载HTML的具体网页URL。