用户登录
用户注册

分享至

上手简单,功能强大的Python爬虫框架——feapder

  • 作者: 我叫常冰川10319618
  • 来源: 51数据库
  • 2021-10-19

简介

feapder 是一款上手简单,功能强大的python爬虫框架,使用方式类似scrapy,方便由scrapy框架切换过来,框架内置3种爬虫:

  • airspider爬虫比较轻量,学习成本低。面对一些数据量较少,无需断点续爬,无需分布式采集的需求,可采用此爬虫。
  • spider是一款基于redis的分布式爬虫,适用于海量数据采集,支持断点续爬、爬虫报警、数据自动入库等功能
  • batchspider是一款分布式批次爬虫,对于需要周期性采集的数据,优先考虑使用本爬虫。

feapder除了支持断点续爬、数据防丢、监控报警外,还支持浏览器渲染下载,自定义入库pipeline,方便对接其他数据库(默认数据库为mysql,数据可自动入库,无需编写pipeline)

读音: [ˈfiːpdə]

  • 官方文档:
  • 国内文档:
  • github:https://github.com/boris-code/feapder
  • 更新日志:https://github.com/boris-code/feapder/releases

环境要求:

  • python 3.6.0+
  • works on linux, windows, macos

安装

from pypi:

通用版

pip3 install feapder

完整版:

pip3 install feapder[all]

通用版与完整版区别:

完整版支持基于内存去重

完整版可能会安装出错,若安装出错,请参考安装问题

小试一下

创建爬虫

feapder create -s first_spider

创建后的爬虫代码如下:

import feapder


class firstspider(feapder.airspider):
    def start_requests(self):
        yield feapder.request("http://www.51sjk.com/Upload/Articles/1/0/254/254279_20210628000427368.com")

    def parse(self, request, response):
        print(response)


if __name__ == "__main__":
    firstspider().start()

直接运行,打印如下:

thread-2|2021-02-09 14:55:11,373|request.py|get_response|line:283|debug|
                -------------- firstspider.parse request for ----------------
                url  = http://www.51sjk.com/Upload/Articles/1/0/254/254279_20210628000427368.com
                method = get
                body = {'timeout': 22, 'stream': true, 'verify': false, 'headers': {'user-agent': 'mozilla/5.0 (windows nt 6.1; wow64) applewebkit/537.36 (khtml, like gecko) chrome/27.0.1453.93 safari/537.36'}}

<response [200]>
thread-2|2021-02-09 14:55:11,610|parser_control.py|run|line:415|debug| parser 等待任务 ...
firstspider|2021-02-09 14:55:14,620|air_spider.py|run|line:80|info| 无任务,爬虫结束

代码解释如下:

  • start_requests: 生产任务
  • parse: 解析数据

将请求头转为json格式

爬虫采集中,我们经常需要携带网站的header等参数,比如:我们在浏览器检查工具看到某请求头为:

accept-encoding: gzip, deflate, br
accept-language: zh-cn,zh;q=0.9,en;q=0.8
cache-control: max-age=0
connection: keep-alive
user-agent: mozilla/5.0 (macintosh; intel mac os x 10_15_4) applewebkit/537.36 (khtml, like gecko) chrome/89.0.4389.90 safari/537.36

如果我们想在发请求时携带这个header,那么需要手动将其转为json格式。

使用

输入命令,回车

> feapder create -j
请输入需要转换的内容:(xxx:xxx格式,支持多行)

输出如下:

另外,feapder还支持创建有序字典,方便对比参数前后的变化

命令为:

feapder create -sj

以上就是上手简单,功能强大的python爬虫框架——feapder的详细内容,更多关于python 爬虫框架feapder的资料请关注其它相关文章!

软件
前端设计
程序设计
Java相关