Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想编写一个 python 脚本,仅当网页包含 HTML 时才下载网页。我知道content-typeinheader将被使用。请建议以某种方式执行此操作,因为我无法header在文件下载之前获得方法。
content-type
header
用于http.client向 URL 发送HEAD请求。这将只返回资源的标头,然后您可以查看content-type标头并查看它是否text/html。如果是,则向GETURL 发送请求以获取正文。
http.client
HEAD
text/html
GET