首页 > 其他 > 详细

用requests库和BeautifulSoup4库爬取新闻列表

时间:2017-09-27 13:02:49      阅读:271      评论:0      收藏:0      [点我收藏+]
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库爬取新闻列表

原文:http://www.cnblogs.com/hxhlo/p/7600940.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!