中国新闻网的新闻种类较多、而且新闻比较丰富,如果需要获取大量新闻的话,中国新闻网是个不错的选择。
界面是这样的:
从url不难发现,改变日期就能获取不同日期的新闻
那么,正文开始。。。
1、获取某一个链接的新闻详情页信息
import requests
from bs4 import BeautifulSoup
url = 'http://www.chinanews.com/auto/2019/01-30/8743035.shtml'
res = requests.get(url)
res.encoding='GBK' # html: ISO-8859-1 (2012)
# res.encoding = 'utf-8' # (2019)
soup = BeautifulSoup(res.text, 'html.parser')
title = soup.find('h1')
print(title.text.strip()