-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweixin_list_rule.js
65 lines (63 loc) · 2.31 KB
/
weixin_list_rule.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
var fs = require('fs');
fs.writeFile('./output/weixin_list.txt', "");
function showList(list) {
console.log(list);
list.list.forEach((item, key) => {
if (item.app_msg_ext_info) {
console.log('标题', item.app_msg_ext_info.title);
console.log('链接', item.app_msg_ext_info.content_url);
console.log('\n');
// console.log(item.app_msg_ext_info.multi_app_msg_item_list);
if (item.app_msg_ext_info.multi_app_msg_item_list.length > 0) {
console.log('多个文章', item.app_msg_ext_info.multi_app_msg_item_list.length);
}
fs.appendFile('./output/weixin_list.txt', item.app_msg_ext_info.content_url + "\n", function(err) {
if (err) {
// console.log('写文件操作失败');
} else {
console.log('写文件操作成功');
}
});
} else {
console.log(item);
}
});
}
module.exports = {
summary: '抓取微信公众号文章列表',
*beforeDealHttpsRequest(requestDetail) {
//console.log('beforeDealHttpsRequest');
return true;
},
*beforeSendRequest(requestDetail) {
//console.log('beforeSendRequest');
},
*beforeSendResponse(requestDetail, responseDetail) {
//console.log('beforeSendResponse');
if (requestDetail.url.indexOf('profile_ext') > 0) {
try {
let bodyjson = JSON.parse(responseDetail.response.body);
if (bodyjson && bodyjson.general_msg_list) {
let general_msg_list = JSON.parse(bodyjson.general_msg_list);
showList(general_msg_list);
}
} catch(e) {
let reg = /var msgList = '(.*)'/;
let res = reg.exec(responseDetail.response.body);
if (res) {
// console.log(responseDetail.response.body + '');
let text = res[1].replace(/"/g, '"');
text = text.replace(/\\\\/g, '');
let json = JSON.parse(text)
showList(json);
}
}
}
},
onError(requestDetail, error) {
console.log('onError', error);
},
onConnectError(requestDetail, error) {
console.log('error', error);
}
};