python爬取糗事百科
来源:互联网 发布:mac air使用教程视频 编辑:程序博客网 时间:2024/06/05 18:58
转载:静觅 »Python爬虫实战一之爬取糗事百科段子
#!/usr/bin/env python# _*_coding:utf-8 _*_# @Time :2017/8/21 23:32# @Author :luoyu_bie# @File :QsBaike.py# @Software :PyCharm Community Editionimport urllib2import repage = 1url = "http://www.qiushibaike.com/hot/page/"+str(page)agent = "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0"headers = {"User-Agent":agent}req = urllib2.Request(url,headers=headers)response = urllib2.urlopen(req)html = response.read()#编译正则表达式pattern = re.compile('<div class="author clearfix">.*?<h2>(.*?)</h2>.*?<div class="content">.*?<span>(.*?)</span>.*?<div class="stats">.*?<i class="number">(\d)</i>',re.S)items = re.findall(pattern,html)for item in items: print "发布者:"+item[0].strip()+"\n","段子:"+"\n"+item[1].strip().replace("<br/>","\n")+"\n"+"点赞数:"+item[2]+"\n"+"*"*10
阅读全文
0 0
- [Python]爬取糗事百科
- python 爬取糗事百科
- python爬取糗事百科
- python爬取糗事百科
- python爬虫爬取糗事百科
- python 爬虫 爬取糗事百科段子
- Python爬虫 爬取糗事百科段子
- Python爬虫爬取糗事百科段子
- python爬虫----爬取糗事百科
- Python爬虫实现爬取糗事百科
- python爬取糗事百科段子
- Python爬虫 爬取糗事百科段子
- python爬虫爬取糗事百科图片
- 爬取糗事百科
- 爬取糗事百科
- 爬取糗事百科
- 爬取糗事百科
- 爬取糗事百科
- MySQL统计信息
- Spring核心原理AOP
- windows部署项目到服务器,文件名中文乱码
- Java 类的生命周期
- mybatis入门实战之CRUD
- python爬取糗事百科
- #支持向量机(SVM)与其理论发展(1)
- MySQL 5.7 EXPLAIN EXTENDED语句说明
- 次小生成树
- debug有感
- Python网络爬虫1
- vue.js 2.0实现的简单分页
- React实现按钮控制倒计时
- 基于vue2.0的一个分页组件