爬取校园网新闻首页的新闻

 

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)

posted on 2018-04-03 18:04  嘻嘻嘻宸  阅读(163)  评论(0编辑  收藏  举报