码迷,mamicode.com
首页 > 编程语言 > 详细

爬虫之多线程,提高效率

时间:2021-02-20 11:52:43      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:gif   style   opened   write   rom   效率   网易云   header   proc   

技术图片
arr = ["http://music.163.com/song/media/outer/url?id=1820550501.mp3",
"http://music.163.com/song/media/outer/url?id=1820550501.mp3",
"http://music.163.com/song/media/outer/url?id=1820550501.mp3",
"http://music.163.com/song/media/outer/url?id=1820550501.mp3",
"http://music.163.com/song/media/outer/url?id=1820550501.mp3",
"http://music.163.com/song/media/outer/url?id=1820550501.mp3",
"http://music.163.com/song/media/outer/url?id=1820550501.mp3",
"http://music.163.com/song/media/outer/url?id=1820550501.mp3",
"http://music.163.com/song/media/outer/url?id=1820550501.mp3",
"http://music.163.com/song/media/outer/url?id=1820550501.mp3",
"http://music.163.com/song/media/outer/url?id=1820550501.mp3"]

import random
def downsong(url):
    res = requests.get(url,headers=headers)
    with open(f"D://music/{str(random.randint(1,100))}.mp3","wb")as f:
        f.write(res.content)

from multiprocessing.dummy import Pool
p = Pool(4)
p.map(downsong,arr)
print("下载完毕")
View Code

下载网易云 使用多线程爬虫

爬虫之多线程,提高效率

标签:gif   style   opened   write   rom   效率   网易云   header   proc   

原文地址:https://www.cnblogs.com/3-wusen/p/14414168.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!