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)