效果:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2020/11/28 18:33
# @Author : huni
# @File : 长电影爬取.py
# @Software: PyCharm
from threading import Thread #多线程的包
from queue import Queue #队列
import requests
import os
class CrawlInfo(Thread):
#重写构造函数
def __init__(self,url_queue):
Thread.__init__(self)
#声明两个类属性
self.url_queue = url_queue
#重写run方法
def run(self):
#爬虫代码
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.93 Safari/537.36'
}
while self.url_queue.empty() == False: #当url队列中不是空的就继续爬