标签:select nts gb2312 port int text soup sele res
import requests from bs4 import BeautifulSoup jq=‘http://news.gzcc.cn/html/2017/xiaoyuanxinwen_0926/8262.html‘ res = requests.get(jq) res.encoding=‘gb2312‘ soup = BeautifulSoup(res.text,‘html.parser‘) for news in soup.select(‘li‘): if len(news.select(‘a‘))>0: title=news.select(‘a‘)[0].text url=news.select(‘a‘)[0][‘href‘] #time=news.select(‘span‘)[0].contents[0].text #print(time,title,url) print(title,url)
用requests库和BeautifulSoup4库爬取新闻列表
标签:select nts gb2312 port int text soup sele res
原文地址:http://www.cnblogs.com/hxhlo/p/7600940.html