博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
爬虫入门【10】Pyspider框架简介及安装说明
阅读量:4516 次
发布时间:2019-06-08

本文共 1334 字,大约阅读时间需要 4 分钟。

Pyspider是python中的一个很流行的爬虫框架系统,它具有的特点如下:

1、可以在Python环境下写脚本
2、具有WebUI,脚本编辑器,并且有项目管理和任务监视器以及结果查看。
3、支持多种数据库
4、支持定义任务优先级,自动重试链接。。。
5、分布式架构
等等优点。

pyspider的设计基础是:以python脚本驱动的抓取环模型爬虫。

教程: http://docs.pyspider.org/en/latest/tutorial/

文档: http://docs.pyspider.org/
发布版本: https://github.com/binux/pyspider/releases

入门范例

from pyspider.libs.base_handler import *class Handler(BaseHandler):    crawl_config = {    }    @every(minutes=24 * 60)    def on_start(self):        self.crawl('http://scrapy.org/', callback=self.index_page)    @config(age=10 * 24 * 60 * 60)    def index_page(self, response):        for each in response.doc('a[href^="http"]').items():            self.crawl(each.attr.href, callback=self.detail_page)    def detail_page(self, response):        return {            "url": response.url,            "title": response.doc('title').text(),        }

【插入图片,Pyspider界面】

993869-20171211213501009-1962863037.png

代码简单介绍

def on_start(self):

这是脚本的入口节点,当我们点击run的时候,程序会自动调用这个函数。

self.crawl(url, callback=self.index_page):

这时最重要的API,将会添加新任务,大部分选项使用crawl的参数来指定。

def index_page(self, response):

这个方法得到一个response对象,然后通过PyQuery的doc命令来解析。

def detail_page(self, response):

返回一个dict对象作为结果。这个结果可以保存到数据库中。

我们还可以在脚本中自定义函数或者对象。

【插入图片,运行界面】

993869-20171211213507555-578138011.jpg

安装

推荐使用Pycharm,在Project Interpreter里面添加pyspider,目前最新的版本是0.3.9.

或者使用pip命令安装。

今天来不及把整个项目内容讲完了,明天继续。

转载于:https://www.cnblogs.com/xingzhui/p/8025148.html

你可能感兴趣的文章
【旧文章搬运】调试没有符号的驱动时如何断在入口点处
查看>>
1301 邻值查找(set 平衡树 | 链表)
查看>>
ssl1692-魔板【HSAH,bfs】
查看>>
[Ramda] Refactor to Point Free Functions with Ramda using compose and converge
查看>>
[Vue + TS] Create your own Decorators in Vue with TypeScript
查看>>
[Python] isinstance() for checking object type
查看>>
[MODx] Build a CMP (Custom manager page) using MIGX in MODX 2.3 -- 1
查看>>
运行osgdem找不到nvtt.dll,以及不能添加纹理图像的解决方法
查看>>
MySQL数值类型
查看>>
flex布局
查看>>
通过HBase Shell与HBase交互
查看>>
java基础--extension package commons(3)
查看>>
基于Lumisoft.NET组件的POP3邮件接收和删除操作
查看>>
JSON日期时间格式转换
查看>>
《计算机组成结构化方法》读书笔记-1
查看>>
jquery 导航固定的一个实例
查看>>
go语言调用cmd
查看>>
jQuery中.bind() .live() .delegate() .on()区别
查看>>
暑假第五测
查看>>
怪盗基德的滑翔翼
查看>>