admin 管理员组

文章数量: 887007

python 并发爬虫的快感

import time
from tomorrow import threads
from requests_html import HTMLSession
session=HTMLSession()
@threads(50)  # 使用装饰器,这个函数异步执行
def download(url):return session.get(url)def main():start = time.time()urls = ['.2.0/','.html','','','.html?yyue=a21bo.50862.201879','.2.0/','.html','','','.html?yyue=a21bo.50862.201879','.2.0/','.html','','','.html?yyue=a21bo.50862.201879','.2.0/','.html','','','.html?yyue=a21bo.50862.201879','.2.0/','.html','','','.html?yyue=a21bo.50862.201879','.2.0/','.html','','','.html?yyue=a21bo.50862.201879','.2.0/','.html','','','.html?yyue=a21bo.50862.201879','.2.0/','.html','','','.html?yyue=a21bo.50862.201879','.2.0/','.html','','','.html?yyue=a21bo.50862.201879','.2.0/','.html','','','.html?yyue=a21bo.50862.201879','.2.0/','.html','','','.html?yyue=a21bo.50862.201879','.2.0/','.html','','','.html?yyue=a21bo.50862.201879','.2.0/','.html','','','.html?yyue=a21bo.50862.201879','.2.0/','.html','','','.html?yyue=a21bo.50862.201879','.2.0/','.html','','','.html?yyue=a21bo.50862.201879','.2.0/','.html','','','.html?yyue=a21bo.50862.201879','.2.0/','.html','','','.html?yyue=a21bo.50862.201879']req_list=[]for i in urls:req_list.append(download(i))print(req_list)responses = [i.html.xpath("//title/text()") for i in req_list]print(responses)end = time.time()print("Time: %f seconds" % (end - start))if __name__ == "__main__":main()

转载于:.html

本文标签: python 并发爬虫的快感