requests 模块例题示范

requests 模块

re模块和requests模块结合示范实例

.*? 不加圆括号表示在要匹配里面的内容不要;

(.*?)表示在要匹配的两者之间的内容都要;

import requests

import re
content_list=[]
response = requests.get('https://ishuo.cn/')
data=response.text
# print(data)
res=re.findall('
(.*?)
',data) res1=re.findall('(.*?)',data) # print(res1) for i in res: if i.startswith('
    '): continue content_list.append(i) with open(r'duanzi.txt','w',encoding='utf8')as f: for j in range(len(content_list)): res2=str(f'\n{j}>>>{res1[j]}:\n {content_list[j]}\n') # print(res2) f.write(res2) f.flush()

转载于:https://www.cnblogs.com/zhangchaocoming/p/11610264.html

你可能感兴趣的:(requests 模块例题示范)