我正在尝试下载mp3文件,使用python,从一个网站有云照明弹。我知道python的“cfscrape”模块,但是如何使用它从url下载文件。
发布于 2016-04-29 23:24:39
这里是下载多个文件从一个'csv‘文件,其中有链接。
注意:我在这里得到了帮助:Python download files by links stored in csv
import csv
import os
import sys
import cfscrape
scraper = cfscrape.create_scraper()
filename = 'nazm_urls.csv'
with open(filename, 'rb') as f:
reader = csv.reader(f)
try:
for row in reader:
if 'http' in row[0]:
reverse = row[0][::-1]
i = reverse.index('/')
tmp = reverse[0:i]
cfurl = scraper.get(row[0]).content
if not os.path.exists("./"+tmp[::-1]):
with open(tmp[::-1], 'wb') as f:
f.write(cfurl)
f.close()
else:
print("file: ", tmp[::-1], "already exists")
except csv.Error as e:
sys.exit('file %s, line %d: %s' % (filename, reader.line_num, e))发布于 2016-04-29 23:06:30
这样啊,原来是这么回事。
import cfscrape
scraper = cfscrape.create_scraper()
url = 'the website url'
cfurl = scraper.get(url).content
name = url.split('/')[-1]
with open(name, 'wb') as f:
f.write(cfurl)https://stackoverflow.com/questions/36948573
复制相似问题