使用fiddler抓取微信公众号文章的阅读数、点赞数、评论数
1 设置fiddler支持https
打开fiddler,在菜单栏中依次选择 [Tools]->[Options]->[HTTPS],勾上如下图的选项:
单击Actions,选择Export Root Certificate to Desktop(导出证书到桌面)选项:
安装证书:
在桌面上找到FiddlerRoot.cer文件,双击进行安装直到导入成功。
2 配置fiddler抓取规则
在菜单栏中依次选择 [Rules]->[Customize Rules] 弹出Fiddler ScriptEditor界面
找到OnBeforeRequest方法和OnBeforeResponse方法
修改OnBeforeRequest方法内容如下:
static function OnBeforeRequest(oSession: Session) { //加在方法末尾 if (oSession.fullUrl.Contains("mp.weixin.qq.com")) { var fso; var file; fso = new ActiveXObject("Scripting.FileSystemObject"); //文件保存路径,可自定义 file = fso.OpenTextFile("c:\\Sessions.txt",8 ,true, true); file.writeLine("Request url: " + oSession.url); file.writeLine("Request header:" + "\n" + oSession.oRequest.headers); file.writeLine("Request body: " + oSession.GetRequestBodyAsString()); file.writeLine("\n"); file.close(); } }
修改OnBeforeResponse方法内容如下:
static function OnBeforeResponse(oSession: Session) { //加在方法末尾 if (oSession.HostnameIs("mp.weixin.qq.com") && oSession.uriContains("https://mp.weixin.qq.com/mp/getappmsgext")){ var filename = "C:/fiddler-token.log"; var curDate = new Date(); var logContent = "[" + curDate.toLocaleString() + "] " + oSession.PathAndQuery + "\r\n"+oSession.GetResponseBodyAsString()+"\r\n"; var sw : System.IO.StreamWriter; if (System.IO.File.Exists(filename)){ sw = System.IO.File.AppendText(filename); sw.Write(logContent); } else{ sw = System.IO.File.CreateText(filename); sw.Write(logContent); } sw.Close(); sw.Dispose(); } }
修改后保存文件。
3 抓取微信公众号文章阅读数、点赞数、评论数。
打开fiddler,打开微信PC客户端,登录微信账号进入客户端,订阅号里点击一篇文章。
fiddler左侧页面里面找到URL显示为/mp/getappmsgext...这一行,单击可看到如下内容:
找到本地log日志:C:/fiddler-token.log打开,内容如下:
[2018年9月14日 19:48:39] /mp/getappmsgext?f=json&mock=&uin=MjE1NjA1NjY0MA%253D%253D&key=4f0ee914ced5da58219044ef4af06a380d5764b71d2c36d0ecf3daa945ff76fecd582d1db95d3d8afe53d5c873e5afcc19ee88aac84d2e42074513a7020d13d351a7fc3fda74fb42920dfbd8674f38fc&pass_ticket=4LNlaufuIWu0x5ZF0Nf2q7%25252BHzHQd6yuWJmeB5q1qBVJvOYFARL4Hu%25252B1hvXa%25252Bgz1k&wxtoken=777&devicetype=Windows%26nbsp%3B7&clientversion=6206034e&appmsg_token=974_QWX6R9iNL8B3cm3q0XALp43vN0BvLLbR5Zmv0wrV91f2e9cawK85Z9tOo3vgr-AI_4gENldeLGOzsOSG&x5=0&f=json {"advertisement_num":0,"advertisement_info":[],"appmsgstat":{"show":true,"is_login":true,"liked":false,"read_num":100001,"like_num":453,"ret":0,"real_read_num":0},"comment_enabled":1,"reward_head_imgs":[],"only_fans_can_comment":false,"comment_count":373,"is_fans":1,"nick_name":"ycyzharry","logo_url":"http:\/\/wx.qlogo.cn\/mmopen\/pdCPMyNrF2ibw23saAW8gyrNhiaibHE9sia3jexyjuvRGLl8OqroTy0hcRickicby6Oq14F47GBEuDdiax2gkxs8IUCYh7yOdmaeJXb\/132","friend_comment_enabled":0,"base_resp":{"wxtoken":777}}
4 设置fiddler抓取过滤
在fiddler右侧界面分页栏中选择 [Filters] 设置内容如下
这样fiddler只会抓取和微信相关的请求响应。