爬取校园新闻

import requests
re=requests.get('http://news.gzcc.cn/html/xiaoyuanxinwen/')
re.encoding='utf-8'
from bs4 import BeautifulSoup
soup = BeautifulSoup(re.text,'html.parser')
for news in soup.select('li'):
    if len(news.select('.news-list-title'))>0:
        t = news.select('.news-list-title')[0].text
        f = news.select('.news-list-description')[0].text
        r = news.select('.news-list-info')[0].text
        l=news.select('a')[0].attrs['href']
        print(t,l)
        print(f,r)

        res = requests.get(l)
        res.encoding = 'utf-8'
        soupd = BeautifulSoup(res.text, 'html.parser')
        print(soupd.select('.show-info')[0].text[0:25])
        print(soupd.select('.show-info')[0].text[30:38])
        print(soupd.select('.show-info')[0].text[38:45])
        print(soupd.select('.show-info')[0].text[46:56])
        print(soupd.select('.show-info')[0].text[62:])
        break

 

posted on 2018-04-04 15:22  184陈楚浩  阅读(83)  评论(0编辑  收藏  举报