可以使用Python中的requests库和BeautifulSoup库来实现爬取网页中的下载列表。以下是一个简单的示例代码:
import requests from bs4 import BeautifulSoup url = 'http://example.com/download-list' response = requests.get(url) if response.status_code == 200: soup = BeautifulSoup(response.content, 'html.parser') download_links = [] for link in soup.find_all('a'): if link.get('href') and link.get('href').endswith('.zip'): download_links.append(link.get('href')) for download_link in download_links: download_response = requests.get(download_link) with open(download_link.split('/')[-1], 'wb') as f: f.write(download_response.content) print('下载完成!') else: print('无法访问网页')
在以上代码中,首先使用requests库获取网页内容,然后使用BeautifulSoup库解析网页,找出所有包含下载链接的标签,并筛选出以’.zip’结尾的链接。最后,依次下载这些链接对应的文件,并保存到本地。