All Projects → ksky521 → mpspider

ksky521 / mpspider

Licence: other
公众号文章抓取&生成kindle电子书

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to mpspider

Pwning Juice Shop
GitBook markdown content for the eBook "Pwning OWASP Juice Shop"
Stars: ✭ 110 (+115.69%)
Mutual labels:  gitbook, ebook, kindle
Blitz
An eBook Framework (CSS + template)
Stars: ✭ 179 (+250.98%)
Mutual labels:  ebook, kindle
InMangaKindle
Descarga manga en español en diferentes formatos (PNG, PDF, EPUB, MOBI)
Stars: ✭ 43 (-15.69%)
Mutual labels:  ebook, kindle
Ethereum Development With Go Book
📖 A little book on Ethereum Development with Go (golang)
Stars: ✭ 754 (+1378.43%)
Mutual labels:  gitbook, ebook
Calibre
The official source code repository for the calibre ebook manager
Stars: ✭ 11,221 (+21901.96%)
Mutual labels:  ebook, kindle
The Economist Ebooks
经济学人(含音频)、纽约客、自然、新科学人、卫报、科学美国人、连线、大西洋月刊、新闻周刊、国家地理等英语杂志免费下载、订阅(kindle推送),支持epub、mobi、pdf格式, 每周更新. The Economist 、The New Yorker 、Nature、The Atlantic 、New Scientist、The Guardian、Scientific American、Wired、Newsweek magazines, free download and subscription for kindle, mobi、epub、pdf format.
Stars: ✭ 3,471 (+6705.88%)
Mutual labels:  ebook, kindle
Laravel Book
Up to date Epub, Mobi and PDF versions from the official Laravel Docs
Stars: ✭ 221 (+333.33%)
Mutual labels:  ebook, kindle
Epub Press Clients
📦 Clients for building books with EpubPress.
Stars: ✭ 370 (+625.49%)
Mutual labels:  ebook, kindle
bitcoin-development-with-go
[Work in Progress] A little book on Bitcoin Development with Go (golang)
Stars: ✭ 19 (-62.75%)
Mutual labels:  gitbook, ebook
Honkit
📖 HonKit is building beautiful books using Markdown - Fork of GitBook
Stars: ✭ 1,901 (+3627.45%)
Mutual labels:  gitbook, ebook
Kindle maker
a tool to make mobi-format file wich could be load into Kindle
Stars: ✭ 70 (+37.25%)
Mutual labels:  ebook, kindle
Bitcoin On Nodejs
《Node.js区块链开发》,注:新版代码已开源!请star支持哦-^-:
Stars: ✭ 2,321 (+4450.98%)
Mutual labels:  gitbook, ebook
Koreader
An ebook reader application supporting PDF, DjVu, EPUB, FB2 and many more formats, running on Cervantes, Kindle, Kobo, PocketBook and Android devices
Stars: ✭ 9,467 (+18462.75%)
Mutual labels:  ebook, kindle
Asciidoctor Epub3
📘 Asciidoctor EPUB3 is a set of Asciidoctor extensions for converting AsciiDoc to EPUB3 & KF8/MOBI
Stars: ✭ 166 (+225.49%)
Mutual labels:  ebook, kindle
Geektime dl
把极客时间装进 Kindle,内含快手内推等福利
Stars: ✭ 1,033 (+1925.49%)
Mutual labels:  ebook, kindle
Libmobi
C library for handling Kindle (MOBI) formats of ebook documents
Stars: ✭ 197 (+286.27%)
Mutual labels:  ebook, kindle
bookery
Manage all your ebooks and send them to your reader
Stars: ✭ 35 (-31.37%)
Mutual labels:  ebook, kindle
ComicBookMaker
Script to fetch webcomics and use them to create ebooks.
Stars: ✭ 27 (-47.06%)
Mutual labels:  ebook, kindle
Network Programming With Go
Network programming with Go
Stars: ✭ 903 (+1670.59%)
Mutual labels:  gitbook, ebook
Spring Boot Book
Spring Boot 开源电子书
Stars: ✭ 178 (+249.02%)
Mutual labels:  gitbook, ebook

公众号文章抓取&生成 kindle 电子书

抓取公众号历史文章,解析成 markdown 文件,生成 gitbook 项目,最后可生成 kindle 书籍。

PS

  1. 需要 ebook-convert 依赖
  2. gitbook 需要在 node 6.x 版本,8.x 不能用,其他没测试
  3. 生成 mobi 需要配置下book.json

抓取方式

支持两种抓取方式:

  1. 从公众号的一篇汇总文章开始,有些公众号会有年度总结文章,比如 这篇文章
  2. 使用 anyproxy 做代理,抓取公众号历史消息文章,忽略非图文类、小标题类文章

PS:汇总文章指的是一个公众号的文章页面,比如「架构师之路」的 这篇文章

流程介绍

  1. 抓取文章
  2. 解析文章内链的外链「公众号文章」
  3. 继续抓取外链文章
  4. 替换外链文章到本地相对地址
  5. 抓取文章内的图片
  6. 替换文章图片到本地相对地址
  7. 生成 gitbook 项目
  8. 使用 gitbook+ebook-convert 生成 kindle 文件

1~6 步是全自动的,7 是看自己情况

安装

npm i mpspider -g

执行方式

# 第一种方式
mpspider article https://mp.weixin.qq.com/s/CIPosICgva9haqstMDIHag -d dest_path
# 第二种方式,需要手动配置代理,点击公众号「查看历史文章」,详见下面介绍,支持手机微信和 pc 微信列表
mpspider proxy -d dest_path -p proxy_port

抓取后,会在dest_path创建 gitbook 项目

生成电子书

执行命令

# 进入抓取后gitbook的地址
cd dest_path
# 创建readme.md,gitbook不创建会报错
touch README.md
# 有必要可以创建book.json,参考gitbook文档
gitbook serve
# 访问地址查看效果
# -------
# 生成电子书
gitbook mobi ./ name.mobi

如何配置 anyproxy 代理抓取 https 页面

配置 anyproxy https 证书

参考:http://anyproxy.io/cn/#%E8%AF%81%E4%B9%A6%E9%85%8D%E7%BD%AE

启动 anyproxy

anyproxy --rule lib/anyproxyRule.js

使用配置文件mpspider.config.js

支持配置项:

  • book.json 配置项:'author', 'title', 'description'
  • summarySort:文章排序函数,方法等同 Array.sort写法,传入item对象,有midtitlecontentreleaseuri等选项,release 是拼音文件名,默认根据 release 排序
  • filter:文章内容过滤函数,将文章列表数组items通过 items.filter(option.filter) 过滤一遍,item 内容包括:midtitlecontent
  • listFilter:列表文章过滤,只用在 proxy 模式下,根据文章列表的 json 对象过滤数据,常用对象字段为
    • app_msg_ext_info:authortitlecopyright_statcontent_urlsource_urldigestcontentcoveris_multi
    • comm_msg_info:datetime发布时间戳
  • turndown:支持keepremoveruleplugins 四个选项,分别对应 turndown 的四个配置项
  • afterConverter:turndown 将 html 转为 markdown 内容之后,将content字符串传入该函数,处理结束后,return处理后的字符串

示例:

const turndownPluginGfm = require('turndown-plugin-gfm');
module.exports = {
    filter: item => {
        if (item.title.indexOf('广告') !== -1) {
            return false;
        }
        return true;
    },
    turndown: {
        keep: 'span',
        remove: 'span',
        rule: {
            strikethrough: {
                filter: ['del', 's', 'strike'],
                replacement: function(content) {
                    return '~' + content + '~';
                }
            }
        },
        plugins: [turndownPluginGfm.gfm, turndownPluginGfm.tables]
    },
    afterConverter: content => {
        return content.replace(/<(.+?)>/g, (i, m) => {
            return `&lt;${m}>`;
        });
    }
};

二次开发

git clone 源码后,进入文件夹,执行npm i

  • index.js 入口文件,使用commanderora进行命令处理
  • getList.js 根据汇总文件提取文章列表
  • proxySpider.js 根据 anyproxy 代理方式抓取
  • dealMPList.js 根据代理抓取使用的文件
  • unfetchMids.js 提取文章列表中内链的文章
  • getImages.js 抓取文章中的图片地址,并且替换为本地地址
  • createBook.js 生成 gitbook markdown 文件和summary.md,替换内链的文内容

电子书依赖

  • ebook-convert:brew install caskroom/cask/calibre
  • gitbook:npm i gitbook-cli -g

kindle 效果截图

目录列表

带图文章

普通文章

给作者加鸡腿

加鸡腿

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].