import requests from fake_useragent import UserAgent import re #设置爬去网站地址 url = "https://www.qiushibaike.com/text/page/11" #url="http://www.7y7.com/tags/272202" headers = { "User-Agent": UserAgent().random } response = requests.get(url, headers=headers) info = response.text infos = re.findall(r'<div class="content">\s*<span>\s*(.+)\s*</span>', info) #infos = re.findall(r'<div class="artcont">\s*<span>\s*(.+)\s*</span>', info) with open("美容信息.txt", "w", encoding="utf-8") as f: for info in infos: f.write(info + "\n\n") print('爬去信息成功')