普通爬糗事百科段子
import urllib.request
import re
import urllib.error
headers = ("User-Agent",'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36')
opener = urllib.request.build_opener()
opener.addheaders = [headers]
urllib.request.install_opener(opener)
for i in range(1,2):
url = 'https://www.qiushibaike.com/text/page/'+str(i)+'/'
pagedata = urllib.request.urlopen(url).read().decode("utf-8","ignore")
pat = '<div class="content">.*?<span>(.*?)</span>.*?</div>'
datas = re.compile(pat,re.S).findall(pagedata)
for data in datas:
print(data)
import threading
class A(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
for i in range(0,10):
print("我是线程A")
class B(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
for i in range(0,10):
print("我是线程B")
t1=A()
t1.start()
t2=B()
t2.start()