爬取糗事百科的笑话,每按一下Enter键,输出一条信息
来源:互联网 发布:淘宝卖衣服需要什么证 编辑:程序博客网 时间:2024/05/21 08:41
这是一个简单的爬虫,爬取糗事百科的笑话,每按一下Enter键,输出一条信息。
'''author:superWangdate:2017-09-14re模板:2.2.1requests模板:2.18.4bs4模板:4.6.0爬取糗事百科的笑话'''#!/usr/bin/env python#-*- coding:utf-8 -*-import requestsfrom bs4 import BeautifulSoupimport reclass GetQiuShiBaiKeInfo(): #得到url中的信息 def getPageInfo(self,url,page): res = requests.get(url) #print(res.text) soup = BeautifulSoup(res.text,"html5lib") articles = soup.select(".article") for article in articles: #得到作者信息 author = article.select(".author")[0].select("h2")[0].text.strip() #得到内容 content = article.select(".content span")[0].text.strip() #得到好笑数 stats_vote = article.select(".stats .stats-vote i")[0].text #得到评论数 stats_comments = article.select(".stats .stats-comments a i")[0].text print(author + "\t内容:" + content + "\t好笑:" + stats_vote + "\t评论:" + stats_comments) #循环直到按下Enter键时才输出 while True: input1 = input() if input1 == '': break print("这一页已看完,需要继续看下一页吗?y:是,n:否") while True: input2 = input() if input2 == 'y': page = page +1 self.getInfo(page) elif input2 == 'n': break else: pass #得到page页的信息 def getInfo(self,page): url = "https://www.qiushibaike.com/hot/page/"+str(page)+"/" self.getPageInfo(url,page)if __name__ == '__main__': a = GetQiuShiBaiKeInfo() a.getInfo(1)
效果图:
阅读全文
0 0
- 爬取糗事百科的笑话,每按一下Enter键,输出一条信息
- Python1--糗事百科笑话爬取
- 爬取糗事百科
- 爬取糗事百科
- 爬取糗事百科
- 爬取糗事百科
- 爬取糗事百科
- 爬取糗事百科的spider
- 爬取糗事百科的段子Demo
- PHP爬取糗事百科首页糗事
- [Python]爬取糗事百科
- 爬取糗事百科段子
- 简单爬取糗事百科
- 爬虫爬取糗事百科
- python 爬取糗事百科
- python爬取糗事百科
- 糗事百科段子爬取
- 爬取糗事百科数据
- 如何在将c++中的Qlist<object*> 注册到qml中并使用
- 静态链接库LIB和动态链接库DLL的区别
- 在html页面中画出逻辑上的二叉树(资源下载)
- 读史笔记--前汉
- 51nod 1267 4个数和为0
- 爬取糗事百科的笑话,每按一下Enter键,输出一条信息
- 输入两个学生的名字和成绩并输出
- Linux在线升级ruby
- python中常用的内建数据结构
- 【MOOC】【分治】4.求排列的逆序数——归并排序的应用
- CodeForces
- vim 配色
- jquery实现仿火车官网城市选择切换案例
- Caffe 中画网络图遇到的错误