import requests
from bs4 import BeautifulSoup
from datetime import datetime

res=requests.get('http://news.gzcc.cn/html/xiaoyuanxinwen/')
res.encoding='utf-8'
soup=BeautifulSoup(res.text,'html.parser')

for news in soup.select('li'):
if len(news.select('.news-list-title'))>0:
d = news.select('.news-list-info')[0].contents[0].text#日期
t = news.select('.news-list-title')[0].text#标题
a = news.select('a')[0].attrs['href']#链接

resd = requests.get(a)
resd.encoding='utf-8'
soupd = BeautifulSoup(resd.text,'html.parser')#新闻详情页

c = soupd.select('#content')[0].text#正文
info=soupd.select('.show-info')[0].text
dt = info.lstrip('发布时间:')[:19]#发布时间
dati = datetime.strptime(dt,':%Y-%m-%d %H:%M:%S')
sh = info[info.find('作者:'):].split()[0].lstrip('作者:')#作者

print(dati,t,a,sh,c)
break



  

 

 

 

 

 

 posted on 2018-04-03 15:55  Runka  阅读(137)  评论(0编辑  收藏  举报