使用fiddler抓取微信公衆號文章的閱讀數、點贊數、評論數

1 設置fiddler支持https

打開fiddler,在菜單欄中依次選擇 [Tools]->[Options]->[HTTPS],勾上以下圖的選項:json

單擊Actions,選擇Export Root Certificate to Desktop(導出證書到桌面)選項:微信

安裝證書:app

在桌面上找到FiddlerRoot.cer文件,雙擊進行安裝直到導入成功。ui

 

2 配置fiddler抓取規則

在菜單欄中依次選擇 [Rules]->[Customize Rules] 彈出Fiddler ScriptEditor界面url

找到OnBeforeRequest方法和OnBeforeResponse方法spa

修改OnBeforeRequest方法內容以下:3d

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();  
        }
}

修改後保存文件。code

 

3 抓取微信公衆號文章閱讀數、點贊數、評論數。

打開fiddler,打開微信PC客戶端,登陸微信帳號進入客戶端,訂閱號裏點擊一篇文章。blog

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只會抓取和微信相關的請求響應。

相關文章
相關標籤/搜索