您的位置:首页 > 编程语言 > Python开发

python爬虫——获取正文内容

2017-08-21 11:23 1031 查看
python爬虫——获取正文内容

import requests
from bs4 import BeautifulSoup
newsurl = "https://news.sina.cn/2017-08-21/detail-ifykcqaw0391535.d.html?from=wap"
res = requests.get(newsurl)
res.encoding = 'utf-8'
#print(res.text)

soup = BeautifulSoup(res.text, 'html.parser')
article = []
for p in soup.select('.art_p')[:-1]:
article.append(p.text.strip())
print(article)

'\n'.join(article)


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python