使用面向对象的方式设计一段python多线程爬虫代码
时间: 2023-02-18 20:22:23 浏览: 154
可以这样:
import threading
import requests
def spider(url):
response = requests.get(url)
print(response.text)
if __name__ == '__main__':
url_list = ['http://www.example.com/1.html', 'http://www.example.com/2.html', 'http://www.example.com/3.html']
threads = []
for url in url_list:
t = threading.Thread(target=spider, args=(url,))
threads.append(t)
t.start()
for t in threads:
t.join()
阅读全文