广商-校园新闻爬虫

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:
        title=news.select('.news-list-title')[0].text #标题
        time=news.select('.news-list-info')[0].contents[0].text#时间
        url1=news.select('a')[0]['href']#url
        bumen=news.select('.news-list-info')[0].contents[1].text#部门
        description=news.select('.news-list-description')[0].text #描述
        print(time,title,bumen,url)
        

 

posted on 2017-09-27 11:25  01-李嘉秀  阅读(132)  评论(0编辑  收藏  举报

导航