标签:标题 png from parse soup 技术分享 requests time odi
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)
标签:标题 png from parse soup 技术分享 requests time odi
原文地址:http://www.cnblogs.com/garxiu/p/7600820.html