下载网站中的所有文件

Download all the files in the website

我需要下载此 link 下的所有文件,其中只有郊区名称在每个 link

中不断变化

仅供参考 https://www.data.vic.gov.au/data/dataset/2014-town-and-community-profile-for-thornbury-suburb

本次搜索下的所有文件link: https://www.data.vic.gov.au/data/dataset?q=2014+town+and+community+profile

有没有可能?

谢谢:)

您可以这样下载文件

import urllib2
response = urllib2.urlopen('http://www.example.com/file_to_download')
html = response.read()

获取页面中的所有链接

from bs4 import BeautifulSoup

import requests
r  = requests.get("http://site-to.crawl")
data = r.text
soup = BeautifulSoup(data)

for link in soup.find_all('a'):
    print(link.get('href'))

您应该先阅读 html,使用 Beautiful Soup 解析它,然后根据您要下载的文件类型找到链接。比如你想下载所有的pdf文件,你可以检查链接是否以.pdf扩展名结尾。

这里有很好的解释和代码:

https://medium.com/@dementorwriter/notesdownloader-use-web-scraping-to-download-all-pdfs-with-python-511ea9f55e48