【发布时间】:2020-06-20 06:08:46
【问题描述】:
我编写了一个代码来抓取网站中的附件。它本质上是抓取附件的超链接。我无法找到一种方法来将这些附件直接保存在本地位置。
import requests
import pandas as pd
from requests import get
url = 'https://www.amfiindia.com/research-information/amfi-monthly'
response = get(url,verify=False)
import bs4
from bs4 import BeautifulSoup
html_soup = BeautifulSoup(response.content,'html.parser')
filetype = '.xls'
excel_sheets = html_soup.find_all('a')
#File name where the links to the excel sheet needs to be saved --> here: "All_Links_2.csv"
destination = open('All_Links_2.csv','wb')
for link in excel_sheets:
href = link.get('href') + '\n'
if filetype in href:
print(href)
有人可以帮忙吗?
【问题讨论】:
-
destination.write(href)而不是print(href)? stackoverflow.com/questions/33289247/…
标签: python beautifulsoup get python-requests