前言
嗨喽!大家好呀,这里是魔王~
模块:- requests >>> pip install requests
- parsel >>> pip install parsel
- re
- 解释器: python 3.8
- 编辑器: pycharm
- 发送请求
- 获取数据
- 解析数据
- 保存数据
代码里一些东西被我删了好过审核,有需要得小伙伴可看评论或私聊我领取~
import requests # 发送请求
import re
# 伪装
headers = {
'cookie': '',
'referer': '',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.84 Safari/537.36',
}
url = ''
html_data = requests.get(url=url, headers=headers).text
info_list = re.findall('(.*?)', html_data)
for link, title in info_list:
link = 'https:' + link
# print(link, title)
# 1. 发送请求
response = requests.get(url=link, headers=headers)
# 2. 获取数据
link_data = response.text
# print(html_data)
# 3. 解析数据
# 网页标签
# (.*?)
text = re.findall('(.*?)', link_data, re.S)[0]
text = text.replace('', '\n')
text = title + '\n\n' + text
print(text)
# 4. 保存数据
with open('网恋女友竟是九天神凰.txt', mode='a', encoding='utf-8') as f:
f.write(text)
尾语
好了,我的这篇文章写到这里就结束啦!
有更多建议或问题可以评论区或私信我哦!一起加油努力叭(ง •_•)ง
喜欢就关注一下博主,或点赞收藏评论一下我的文章叭!!!