编程语言
首页 > 编程语言> > python爬取网页美文网文章内容

python爬取网页美文网文章内容

作者:互联网

respone = requests.get('https://www.meiwen.com.cn/article/58030.html')
#解析获取到的网页信息
result_list = BeautifulSoup(respone.text,'lxml')
#在解析的信息中查找p标签,
soup = result_list.select('p')
#将soup列表转换为文本格式,并且保存到txt文件中
for result in soup:
res = result.text
# print(res)
with open('D:\download\meiwen.txt', 'a',encoding='utf-8') as file:
file.write(res)
print('success')

标签:respone,python,res,美文,爬取,soup,result,file,text
来源: https://www.cnblogs.com/hfct/p/11175248.html