前面的例子为大家介绍爬虫技术,我们发现都是单线程例子,获取的时间相对较慢。那么有没有一种更快速的处理办法呢?这里为大家介绍ThreadPool
中map
方法
from multiprocessing.dummy import Pool as ThreadPool
def getSource(url):
return requests.request(method='GET', url=url, headers=headers, timeout=10, proxies={'http': '123.55.106.175:9999'})
urls = []
for div in _divs:
# 文章地址
href = div.xpath('h4/a/@href')
urls.append(href[0])
pool = ThreadPool(4)
pool.map(getSource, urls)
pool.close()
pool.join()
本文地址:https://blog.csdn.net/jun118166/article/details/107083016
如对本文有疑问, 点击进行留言回复!!
听课笔记--Python数据分析--Numpy基础及基本应用
Python-定时任务APScheduler中两种调度器的区别
网友评论