python3.4学习笔记(十三) 网络爬虫实例代码,使用pyspider抓取多牛投资吧里面的文章信息
PySpider:一个国人编写的强大的网络爬虫系统并带有强大的WebUI,采用Python语言编写,分布式架构,支持多种数据库后端,强大的WebUI支持脚本编辑器,任务监视器,项目管理器以及结果查看器。

用pyspider的demo页面创建了一个爬虫,写一个正则表达式抓取多牛网站上特定的URL,很容易就得到想要的结果了,可以非常方便分析抓取页面里面的内容
binux/pyspider · GitHub
https://github.com/binux/pyspider

http://docs.pyspider.org/en/latest/

Dashboard - pyspider
http://demo.pyspider.org/

ztest - Debugger - pyspider
http://demo.pyspider.org/debug/ztest
那个demo网站还可以直接在线保存自己创建编辑过的代码的
看了pyspider的源码web端是用tornado框架做的,使用 PhantomJS 渲染带 JS 的页面
首页 - Binuxの杂货铺
http://blog.binux.me/
这个是作者的中文博客,有中文的教程文章

=================================

先上直观的效果图:

下面是相关代码:

#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# Created on 2015-07-01 11:04:40
# Project: ztest from pyspider.libs.base_handler import * import re class Handler(BaseHandler):
crawl_config = {
} @every(minutes=24 * 60)
def on_start(self):
self.crawl('http://www.duoniu.cn/club', callback=self.index_page) @config(age=10 * 24 * 60 * 60)
def index_page(self, response):
for each in response.doc('a[href^="http"]').items():
matchObj = re.match( r'(.*).html', each.attr.href, re.M|re.I)
if matchObj:
self.crawl(each.attr.href, callback=self.detail_page) @config(priority=2)
def detail_page(self, response):
return {
"url": response.url,
"title": response.doc('title').text(),
"http-equiv":response.doc('meta').attr('http-equiv'),
"keywords":response.doc('meta[name="keywords"]').attr('content'),
} ===========================================
{
"fetch": {},
"process": {
"callback": "index_page"
},
"project": "ztest",
"schedule": {
"age": 864000
},
"taskid": "0a7f73fcbef54f29761aeeff6cc2ab68",
"url": "http://www.duoniu.cn/club/"
}
=============================================
{
"fetch": {},
"process": {
"callback": "detail_page"
},
"project": "ztest",
"schedule": {
"priority": 2
},
"taskid": "56d325537a7d3ff4c55c3d642aee4eec",
"url": "http://www.duoniu.cn/club/7485.html"
}
================================================
{'http-equiv': 'Content-Type',
'keywords': u'多牛传记,大禹节水,冠昊生物,股票,模拟炒股,股评',
'title': u'多牛客服_乐者,为王——多牛网专访乐者为王 - 多牛网投资吧',
'url': 'http://www.duoniu.cn/club/7485.html'}

新增一个抓取政府新闻的代码:

 #!/usr/bin/env python
# -*- encoding: utf-8 -*-
# Created on 2015-10-09 13:51:35
# Project: xinwen
#http://demo.pyspider.org/debug/xinwen from pyspider.libs.base_handler import * import re class Handler(BaseHandler):
crawl_config = {
} @every(minutes=24 * 60)
def on_start(self):
self.crawl('http://www.gov.cn/xinwen/', callback=self.index_page) @config(age=10 * 24 * 60 * 60)
def index_page(self, response):
for each in response.doc('a[href^="http"]').items():
matchObj = re.match( r'(.*).htm', each.attr.href, re.M|re.I)
if matchObj:
self.crawl(each.attr.href, callback=self.detail_page) @config(priority=2)
def detail_page(self, response):
return {
"url": response.url,
"title": response.doc('title').text(),
"http-equiv":response.doc('meta').attr('http-equiv'),
"keywords":response.doc('meta[name="keywords"]').attr('content'),
}

python3.4学习笔记(十三) 网络爬虫实例代码,使用pyspider抓取多牛投资吧里面的文章信息,抓取政府网新闻内容的更多相关文章

  1. python3.4学习笔记(十七) 网络爬虫使用Beautifulsoup4抓取内容

    python3.4学习笔记(十七) 网络爬虫使用Beautifulsoup4抓取内容 Beautiful Soup 是用Python写的一个HTML/XML的解析器,它可以很好的处理不规范标记并生成剖 ...

  2. python3.4学习笔记(十四) 网络爬虫实例代码,抓取新浪爱彩双色球开奖数据实例

    python3.4学习笔记(十四) 网络爬虫实例代码,抓取新浪爱彩双色球开奖数据实例 新浪爱彩双色球开奖数据URL:http://zst.aicai.com/ssq/openInfo/ 最终输出结果格 ...

  3. python3.4学习笔记(二十三) Python调用淘宝IP库获取IP归属地返回省市运营商实例代码

    python3.4学习笔记(二十三) Python调用淘宝IP库获取IP归属地返回省市运营商实例代码 淘宝IP地址库 http://ip.taobao.com/目前提供的服务包括:1. 根据用户提供的 ...

  4. python3.4学习笔记(二十六) Python 输出json到文件,让json.dumps输出中文 实例代码

    python3.4学习笔记(二十六) Python 输出json到文件,让json.dumps输出中文 实例代码 python的json.dumps方法默认会输出成这种格式"\u535a\u ...

  5. python3.4学习笔记(二十五) Python 调用mysql redis实例代码

    python3.4学习笔记(二十五) Python 调用mysql redis实例代码 #coding: utf-8 __author__ = 'zdz8207' #python2.7 import ...

  6. python3.4学习笔记(十一) 列表、数组实例

    python3.4学习笔记(十一) 列表.数组实例 #python列表,数组类型要相同,python不需要指定数据类型,可以把各种类型打包进去#python列表可以包含整数,浮点数,字符串,对象#创建 ...

  7. python3.4学习笔记(十) 常用操作符,条件分支和循环实例

    python3.4学习笔记(十) 常用操作符,条件分支和循环实例 #Pyhon常用操作符 c = d = 10 d /= 8 #3.x真正的除法 print(d) #1.25 c //= 8 #用两个 ...

  8. java之jvm学习笔记十三(jvm基本结构)

    java之jvm学习笔记十三(jvm基本结构) 这一节,主要来学习jvm的基本结构,也就是概述.说是概述,内容很多,而且概念量也很大,不过关于概念方面,你不用担心,我完全有信心,让概念在你的脑子里变成 ...

  9. python3.4学习笔记(二十四) Python pycharm window安装redis MySQL-python相关方法

    python3.4学习笔记(二十四) Python pycharm window安装redis MySQL-python相关方法window安装redis,下载Redis的压缩包https://git ...

随机推荐

  1. HDU 5762

    Teacher Bo Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Tot ...

  2. 导出excel时,以form方式提交json数据

    今天在写项目时写到一个excel的导出,开始想用ajax请求后台后导出,但发现ajax会有返回值,而且ajax无法直接输出文件,而后台的excel导出方法已经封装好,不方便修改. 就改用了提交的方式f ...

  3. 牛人整理分享的面试知识:操作系统、计算机网络、设计模式、Linux编程,数据结构总结 转载

    基础篇:操作系统.计算机网络.设计模式 一:操作系统 1. 进程的有哪几种状态,状态转换图,及导致转换的事件. 2. 进程与线程的区别. 3. 进程通信的几种方式. 4. 线程同步几种方式.(一定要会 ...

  4. .NET 页面间传值的几种方法

    1. QueryString 这是最简单的传值方式,但缺点是传的值会显示在浏览器的地址栏中且不能传递对象,只适用于传递简单的且安全性要求不高的数值. 传递: location.href="W ...

  5. centos MariaDB10.1.X galera cluster

    [mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.1.12/centos6-amd64 gpgkey=https://yum.m ...

  6. centos6 系统优化脚本

    #!/bin/bash # 检查是否为root用户,脚本必须在root权限下运行 # if [[ "$(whoami)" != "root" ]]; then ...

  7. 文件代码对比软件 Beyond Compare

    Beyond Compare https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&tn=baidu&wd=Beyond%20Co ...

  8. MUI - Dialog 提示窗

    Mui基本简介 MUI不依赖任何第三方JS库,压缩后的JS和CSS文件仅有100+K和60+K MUI的开发手册和下载地址 http://dev.dcloud.net.cn/mui/ui/ https ...

  9. Bootstrap css背景图片的设置

    一. 网页中添加图片的方式有两种 一种是:通过<img>标签直接插入到html中 另一种是:通过css背景属性添加 居中方法:水平居中的text-align:center 和 margin ...

  10. Print all nodes at distance k from a given node

    Given a binary tree, a target node in the binary tree, and an integer value k, print all the nodes t ...