这不仅仅是一个作业
1.使用以上代代码下载所有的歌曲!歌曲名最好用已有的.
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('D:\\pythonStudy\\作业题\\HomeWork5\\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('D:\\pythonStudy\\homework\\homewokrday05\\music\\'+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给拿到
2.1 做进程划分,爬取章节页面详情存储到本地,一个章节一个html文件.
2.2 html = response.text
2.3 如果你的请求返回出来的是乱码,设置response.encoding=‘utf-8’/‘gbk’…
2.4 你把文章的内容给拿出来存到本地.
import requests
import multiprocessing
def text (path):
list1 = []
response = requests.get(path)
html = response.text
for line in html.split():
if 'href' in line and 'chapter' in line :
list1.append(line)
return list1
http = text('https://www.17k.com/list/3015690.html')
def A(http):
i = -1
for path_ in http:
i +=1
response = requests.get(path_)
txt_ = response.content
with open('D:\\pythonStudy\\homework\\homewokrday05\\novel\\'+http[i]+'.txt',mode='wb') as f:
f.write(txt_)
if __name__ == "__main__":
p1 = multiprocessing.Process(target = A,args=(http,))
p1.start()
p1.join()
今天的作业写完了又到了每日分享头像的环节了
喜欢的同学请自行拿走
如果喜欢博客的话 请点赞收藏加转发 晚上能不能吃到鸡腿就看大家的了
谢谢观看 再见