我需要使用Python的urllib下载整个网站,就像这样:
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/
wget
无关,你问的是在Python中是否可能(特别是使用urllib),但是它不可能。然而,例如BeautifulSoup
具有此功能,就像wget、scrapy和其他一些工具一样。但是urllib没有,我给你提供的重复链接展示了如何在BeautifulSoup
中实现它(顺便说一下,我讨厌那个名字,太长了):P - Torxed