您好,欢迎来到飒榕旅游知识分享网。
搜索
您的当前位置:首页第四课 Python爬虫简单爬取新浪新闻列表

第四课 Python爬虫简单爬取新浪新闻列表

来源:飒榕旅游知识分享网

输出h2:

res = requests.get('http://news.sina.com.cn/china/')

res.encoding = 'utf-8'

soup = BeautifulSoup(res.text,'html.parser')

for news in soup.select('.news-item'):

if( len(news.select('h2')) >0 ):

print(news.select('h2')[0])


.text

如法炮制:

获取新闻时间标题超链接

res = requests.get('http://news.sina.com.cn/china/')

res.encoding = 'utf-8'

soup = BeautifulSoup(res.text,'html.parser')

for news in soup.select('.news-item'):

if( len(news.select('h2')) >0 ):

h2 = news.select('h2')[0].text

time = news.select('.time')[0].text

a = news.select('a')[0]['href']

print(time,h2,a)


作者QQ:10997180

Github开源项目:


因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- sarr.cn 版权所有 赣ICP备2024042794号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务