首页 > 其他 > 详细

爬取校园新闻首页的新闻

时间:2018-04-03 11:59:31      阅读:291      评论:0      收藏:0      [点我收藏+]

import requests
from bs4 import BeautifulSoup

url="http://news.gzcc.cn/html/xiaoyuanxinwen/"
res=requests.get(url)
res.encoding="utf-8"

soup=BeautifulSoup(res.text,‘html.parser‘)
# for news in soup.select(‘li‘):
# if len(news.select(‘.news-list-title‘)) >0:
# print(news.select(‘.news-list-title‘))


for newc in soup.select(‘li‘):
if len(newc.select(‘.news-list-title‘))>0:
d=newc.select(‘a‘)[0].attrs[‘href‘]
res1=requests.get(d)
res1.encoding="utf-8"
e=BeautifulSoup(res1.text,‘html.parser‘)
content=e.select(‘#content‘)[0].text
show=e.select(‘.show-info‘)[0].text
print(content,show)

爬取校园新闻首页的新闻

原文:https://www.cnblogs.com/XiaoFengLuo/p/8707450.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!