import requests
import parsel
import threading
urls=[
f'https://www.cnblogs.com/cate/python/#p{page}'
for page in range(1,87)
]
def get_request(url):
response=requests.get(url)
selector=parsel.Selector(response.text)
title_data = selector.css('div.post-item-text > a::text').getall()
link_data = selector.css('div.post-item-text > a::attr(href)').getall()
for title,link in zip(title_data,link_data):
print(title, link)
def multi_thread():
print("multi_thread begin")
threads=[]
for url in urls:
threads.append(
threading.Thread(target=get_request,args=(url,))
)
# 开启线程
for thread in threads:
thread.start()
#等待结束
for thread in threads:
thread.join()
print("multi_thread end")
if name == 'main':
start=time.time()
multi_thread()
end=time.time()
print("multi thread cost:",end-start,"seconds")
这样?