第一种 threading.Thread
import threading
import requests
from bs4 import BeautifulSoup
import re
import time
import queue
course_url = 'xxxxxxxxxxx'
pattern = re.compile(r'')
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36'}
# 创建线程类,继承Thread类
# class MyThread(threading.Thread):
# def __init__(self, func, args):
# super(MyThread, self).__init__()
# self.func = func
# self.args = args
#
# def run(self):
# self.func(*self.args)
def extra_links(q, f):
"""
用于多线程采集
:param q: url 队列
:param f: 写入的目标文件