python 爬取段子网段子写入文件

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} \n")
# d段子写入文件
f = open('test.txt','a',encoding = 'utf-8')

    f.write(f"{j} \r")
posted @ 2019-07-28 13:39  来年若相见  阅读(184)  评论(0编辑  收藏  举报