下载HTML页面及其内容 [英] Download HTML page and its contents

查看:59
本文介绍了下载HTML页面及其内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Python 是否可以将整个HTML页面及其内容( images,css )下载到给定URL的本地文件夹中.并更新本地html文件以在本地选择内容.

Does Python have any way of downloading an entire HTML page and its contents (images, css) to a local folder given a url. And updating local html file to pick content locally.

推荐答案

您可以使用

You can use the urllib module to download individual URLs but this will just return the data. It will not parse the HTML and automatically download things like CSS files and images.

如果要下载整个"页面,则需要解析HTML并找到需要下载的其他内容.您可以使用Beautiful Soup 之类的方法来解析检索到的HTML

If you want to download the "whole" page you will need to parse the HTML and find the other things you need to download. You could use something like Beautiful Soup to parse the HTML you retrieve.

此问题中有一些示例代码正是这样做的.

This question has some sample code doing exactly that.

这篇关于下载HTML页面及其内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆