下载歌曲!歌曲名最好用已有的.
import json
import multiprocessing
import requests
#获取歌曲链接
def text (path):
list1 = []
list2 = []
with open(path,mode=‘r’) as f:
res = f.readlines()[0].strip(’\n’).split(’}’)
for json_ in res[:-1]:
json = json + ‘}’
_json = json.loads(_json)
song_play_url = _json[‘song_play_url’]
if song_play_url is not None:
list1.append(song_play_url)
song_name = _json[‘song_name’]
list2.append(song_name)
return list1 , list2
song_url,song_name = text(‘C:\Users\john\Documents\Python\day05_xiancheng\top_500.txt’)
#下载歌曲
def A(song_url,song_name):
i = -1
for path in song_url:
i += 1
response = requests.get(path)
mp3_ = response.content
with open(‘C:\Users\john\Documents\Python\day05_xiancheng\gedan\’+song_name[i]+’.mp3’,mode=‘wb’) as f:
f.write(mp3_)
if name == “main”:
x = int(len(song_url)/2)
p1 = multiprocessing.Process(target = A,args=(song_url[0:x],song_name[0:x]))
p2 = multiprocessing.Process(target = A,args=(song_url[x:],song_name[x:]))
p1.start()
p2.start()
p1.join()
p2.join()
————————————————
2、想办法把 https://www.17k.com/list/3015690.html 页面中章节详情的内容URL给拿到
1)做进程划分,爬取章节页面详情存储到本地,一个章节一个html文件.
2) html = response.text
3) 如果你的请求返回出来的是乱码,设置response.encoding=‘utf-8’/‘gbk’…
4)你把文章的内容给拿出来存到本地.
————————————————
版权声明:本文为优快云博主「wangzhangni」的原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接及本声明。
原文链接: