All Projects → f111fei → Article_spider

f111fei / Article_spider

微信公众号爬虫

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to Article spider

Wechatbot4xianyu
🤖 微信订阅机器人 | 🐟 微信订阅机器人之闲鱼二手商品监控
Stars: ✭ 56 (-76.17%)
Mutual labels:  spider, wechat
Weixin Spider
微信公众号爬虫,公众号历史文章,文章评论,文章阅读及在看数据,可视化web页面,可部署于Windows服务器。基于Python3之flask/mysql/redis/mitmproxy/pywin32等实现,高效微信爬虫,微信公众号爬虫,历史文章,文章评论,数据更新。
Stars: ✭ 287 (+22.13%)
Mutual labels:  spider, wechat
Examples Of Web Crawlers
一些非常有趣的python爬虫例子,对新手比较友好,主要爬取淘宝、天猫、微信、豆瓣、QQ等网站。(Some interesting examples of python crawlers that are friendly to beginners. )
Stars: ✭ 10,724 (+4463.4%)
Mutual labels:  spider, wechat
Wechat articles spider
微信公众号文章的爬虫
Stars: ✭ 993 (+322.55%)
Mutual labels:  spider, wechat
Wechat article
爬取微信公众号文章
Stars: ✭ 121 (-48.51%)
Mutual labels:  spider, wechat
Spiderkeeper
admin ui for scrapy/open source scrapinghub
Stars: ✭ 2,562 (+990.21%)
Mutual labels:  spider
Wechat
WeChat SDK for Go (微信SDK:简单、易用)
Stars: ✭ 3,144 (+1237.87%)
Mutual labels:  wechat
Wx Promise Request
解决微信小程序 wx.request 请求的并发数限制、不支持异步问题
Stars: ✭ 226 (-3.83%)
Mutual labels:  wechat
Wechatblog
💘微信小程序 & 个人博客 & WordPress & WordPress REST API
Stars: ✭ 223 (-5.11%)
Mutual labels:  wechat
Wechat Database
破解微信数据库 获取想要的数据
Stars: ✭ 236 (+0.43%)
Mutual labels:  wechat
Transferee
一个帮助您完成从缩略视图到原视图无缝过渡转变的神奇框架
Stars: ✭ 2,697 (+1047.66%)
Mutual labels:  wechat
Wechat H5 Boilerplate
为腾讯微信优化的H5动效模板,帮助你快速构建全屏滚动型H5页面。
Stars: ✭ 2,571 (+994.04%)
Mutual labels:  wechat
Oh My Wechat
微信小助手的安装 / 更新工具。
Stars: ✭ 2,756 (+1072.77%)
Mutual labels:  wechat
Jh flutter demo
a flutter demo
Stars: ✭ 229 (-2.55%)
Mutual labels:  wechat
Laravel Crawler Detect
A Laravel wrapper for CrawlerDetect - the web crawler detection library
Stars: ✭ 227 (-3.4%)
Mutual labels:  spider
Spider job
招聘网数据爬虫
Stars: ✭ 234 (-0.43%)
Mutual labels:  spider
Oejia weshop
odoo 微信小程序商城模块 (WeChat Mini Program for Odoo)
Stars: ✭ 224 (-4.68%)
Mutual labels:  wechat
Wxapp Scalc
💬微信小程序版简易计算器demo,适合入门练手
Stars: ✭ 230 (-2.13%)
Mutual labels:  wechat
Weapp
🐧 微信小程序组件和功能封装,基于微信Component自定义组件开发
Stars: ✭ 235 (+0%)
Mutual labels:  wechat
Miaow
A set of plugins for Sketch include drawing links & marks, UI Kit & Color sync, font & text replacing.
Stars: ✭ 2,536 (+979.15%)
Mutual labels:  wechat

微信公众号爬虫

  • [x] 爬取公众号所有文章数据
  • [x] 支持自动识别验证码
  • [x] 离线数据库,包含文章原始信息,文章图片
  • [x] 微信文章预览
  • [ ] 命令行方式调用

效果预览

控制台输出:

文章数据:

HTML预览:

实现原理

目前支持两种方式爬取文章。

1.搜狗微信

通过搜狗微信的搜索结果来抓取文章。

优点:这种方式不需要登录认证,操作简单。

缺点:只能抓取最近10条数据。

使用场景:适合配置定时抓取任务,来获取大量数据。

2.Ajax请求

截获微信公众号文章列表的Ajax请求参数,模拟微信客户端读取文章列表和文章信息。

优点:能获取公众号所有文章数据。

缺点:需要登录微信,并且通过工具手动设置Cookie等参数,才能使用。

使用场景:一次性大量抓取公众号数据,抓取完后配合搜狗法更新数据。

如何使用

必要环境

NodeJS & NPM, Chrome浏览器, 微信桌面客户端(Mac 或者 Windows都可)

初始化环境和编译

git clone [email protected]:f111fei/article_spider.git
cd article_spider
npm install typescript -g
npm install
tsc

配置Config

设置项目根目录下的config.json文件。字段定义如下:

interface Config {
    // 必填,要抓取的微信公众号名称。
    name: string;
    // 可选,若快打码平台的账号密码。用于搜狗抓取模式下自动识别验证码。
    ruokuai: {
        username: string;
        password: string;
    };
    wechat: {
        // 可选,要抓取文章的起始页,默认0
        start?: number;
        // 可选,要抓取的文章数,默认不限制
        maxNum?: number;
        // 可选,抓取模式(sougou, all)。默认all
        mode?: string;
        // 抓取模式为all时有效,公众号的biz字段,获取方法参见下面
        biz?: string;
        // 抓取模式为all时有效,当前cookie字段,获取方法参见下面
        cookie?: string;
        // 抓取模式为all时有效,当前appmsg_token字段,获取方法参见下面
        appmsg_token?: string;
    };
}

获取Ajax请求参数

如果抓取模式为sougou,请跳过此节。

要获取文章列表的Ajax请求数据,需要对获取文章列表数据的请求进行抓包,找到biz,cookie,appmsg_token等关键参数。下面介绍如何抓取请求参数。

以抓取NASA爱好者这个公众号为例。

1.打开公众号 --- 右上角 --- 点击查看历史消息

注意: 配置里面的name字段,应该填写这里的微信号nasawatch,而不是NASA爱好者

2.在打开的窗口中,点击菜单栏上的用默认浏览器(Chrome)打开,使用Chrome打开文章列表页。

3.如果在浏览器中打开出现 请在微信客户端打开链接。 的提示,说明这个URL经过加密了,请按照下面操作获取正确的URL。否则跳过此步。

关闭微信客户端,找到微信桌面客户端可执行程序的位置。使用命令行启动程序:

Windows下通常是:

"C:\Program Files (x86)\Tencent\WeChat\WeChat.exe" --remote-debugging-port=9222

Mac下通常是:

"/Applications/WeChat.app/Contents/MacOS/WeChat" --remote-debugging-port=9222

按照步骤1打开历史消息页。

使用Chrome浏览器打开URL  http://127.0.0.1:9222/json

复制url字段,在新标签页中打开,就可以看到正确的历史消息页了。

4.在历史消息页中,点击右键 ---- 检查,打开Chrome开发者工具 ---- 切换到Network页签 ---- 刷新浏览器。在右侧找到cookie, biz, appmsg_token等字段填入config.json中。

需要向下滚动列表页加载下一页找到 https://mp.weixin.qq.com/mp/profile_ext?action=getmsg 开头的请求,查看其参数。

这些字段可能几个小时之后就会失效,可以重新按照以上步骤重新获取。

启动爬虫

npm start

爬到的文章信息,图片,文章原始数据会存入项目根目录的db文件夹下。

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].