.*?
(.*?)',html.text,re.S) #第一個正則是為了匹配換行符
laughs = re.findall('
(\d+)',html.text,re.S)
comments = re.findall('(\d+) 評論',html.text,re.S)
for name,centent,laugh,comment in zip(names,centents,laughs,comments):
info = {
'name':name,
'centent':centents,
'laugh':laughs,
'comment':comments
}
return (info)
if __name__ == '__main__':
urls = ["https://www.qiushibaike.com/text/page/{}/".format(num)for num in range(0,14)]
start_1 = time.time()
for url in urls:
get_info(url)
end_1 = time.time()
print('串行爬取花費(fèi)時間:' + str(end_1 - start_1))
start_2 = time.time()
pool = Pool(processes=2) #創(chuàng)建進(jìn)程池,processes為設(shè)置的進(jìn)程個數(shù)
pool.map(get_info,urls) #利用map()函數(shù)運(yùn)行進(jìn)程,參數(shù)fuc為運(yùn)行的函數(shù),iterable為迭代參數(shù)
end_2 = time.time()
print('2個進(jìn)程:' + str(end_2 - start_2))
start_3 = time.time()
pool = Pool(processes=4) # 創(chuàng)建進(jìn)程池,processes為設(shè)置的進(jìn)程個數(shù)
pool.map(get_info, urls) # 利用map()函數(shù)運(yùn)行進(jìn)程,參數(shù)fuc為運(yùn)行的函數(shù),iterable為迭代參數(shù)
end_3 = time.time()
print('4個進(jìn)程:' + str(end_3 - start_3))輸出:
創(chuàng)新互聯(lián)建站專業(yè)為企業(yè)提供尼河口網(wǎng)站建設(shè)、尼河口做網(wǎng)站、尼河口網(wǎng)站設(shè)計(jì)、尼河口網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)與制作、尼河口企業(yè)網(wǎng)站模板建站服務(wù),10余年尼河口做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡(luò)服務(wù)。
D:\Python\venv\Scripts\python.exe D:/Python/venv/test12.py
串行爬取花費(fèi)時間:5.043288469314575
2個進(jìn)程:3.351191759109497
4個進(jìn)程:2.882164716720581
Process finished with exit code 0
新聞標(biāo)題:多進(jìn)程爬取
文章轉(zhuǎn)載:http://weahome.cn/article/jdgscj.html