import requests
import re
进入网址
for i in range(1,5):
page_url = requests.get(f"http://duanziwang.com/page/{i}/")
page_content = page_url.text
# print(page_content)
# title_list = page_content
# 得到段子
p_content = re.findall('
(.*?)
',page_content)for j in p_content:
# j = ''.join(j.split())
# print(f"{j} ")
# d段子写入文件
f = open('test.txt','a',encoding = 'utf-8')
f.write(f"{j}
")