我需要使用python urlib下载整个网站 就像
import urllib
site = urllib.urlopen('http://www.mathrubumi.com/index.php')
site_data = site.read()
它只下载第一页。那是index.php。我如何才能使代码下载整个网站。
通过循环??
还是有别的办法?
例如在wget
中,代码中不需要循环
wget \ --recursive \--no-clobber \ --page-requisites \ --html-extension \ --convert-links \
--restrict-file-names=windows \ --domains website.org \ --no-parent \ www.website.org/tutorials/html/
自从用户(在另一个问题中被问到但被删除是因为。。原因..)指出了使用BeautifulSoup作为替代方法的参考,下面是一个工作示例,用于检索所有
<a href="something.html">something</a>
链接并将其保存在本地:注意:目前还没有在锁定的机器上进行测试,因此可能会出现语法错误,但想法是一样的:
如果你想下载一个完整的带有
urllib
的网站,你必须解析每个页面,找到所有链接并下载它们。这是可行的,但要做到正确却很难。如果您想要纯python解决方案,我建议您查看scrapy,或者从脚本中调用
wget
。相关问题 更多 >
编程相关推荐