爬虫学习笔记1——爬取糗百段子
来源:互联网 发布:未来造价软件 编辑:程序博客网 时间:2024/06/06 19:48
教程原文
# -*- coding: utf-8 -*-import urllib2import repage = 1url = 'https://www.qiushibaike.com/' + str(page)user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'headers = {'User-Agent': user_agent}try: request = urllib2.Request(url, headers=headers) response = urllib2.urlopen(request) content = response.read().decode('utf-8') pattern = re.compile('<div class="author.*?>[\s\S]*?<a.*?>[\s\S]*?<img.*?alt=(.*?)>[\s\S]*?</div>[\s\S]*?' +'<div class="content">\n<span>([\s\S]*?)</span>[\s\S]*?<!--.*?-->([\s\S]*?)<div class="stats">', re.S) items = re.findall(pattern, content) for item in items: haveImg = re.search("img", item[2]) if not haveImg: print item[0],item[1] #print itemsexcept urllib2.URLError, e: if hasattr(e, "code"): print e.code if hasattr(e, "reason"): print e.reason
阅读全文
0 0
- 爬虫学习笔记1——爬取糗百段子
- python爬虫学习笔记1——糗百段子爬取
- python爬虫学习——爬取糗百页面段子
- 网络爬虫——爬取糗事百科笑料段子
- 爬虫 —— 学习笔记
- Python3爬虫学习笔记1.0——什么是爬虫?
- 网络爬虫学习笔记——网络爬虫简介
- pythpn学习の爬虫爬取糗事百科热门段子
- python爬虫学习笔记——使用requests库编写爬虫(1)
- Python爬虫教程——实战一之爬取糗事百科段子
- Python爬虫教程——实战一之爬取糗事百科段子
- 爬虫-糗事百科段子
- 爬虫 内涵段子
- python 爬虫糗事段子中的段子
- 学习python爬虫笔记(1)
- 初学爬虫,爬取糗百段子(修改版,亲测)
- Python爬虫实战(1):爬取糗事百科段子
- Python爬虫实战(1):爬取糗事百科段子
- angulas.js 增删改查
- [LeetCode]98. Validate Binary Search Tree
- . 报错 specified child already has a parent. You must call removeView() on the child's parent first
- ngrx 初探
- 单链表
- 爬虫学习笔记1——爬取糗百段子
- [Go]hello world
- 字符串输入、输出
- HDU
- 从豆瓣电影评分算法说起
- base64图片文件上传实例
- Qt之QLabel
- CentOS7使用firewalld控制防火墙,以及使用iptables设置
- 理解OAuth 2.0