1.Anyproxy 安装教程:参考其他同学的教程 https://www.jianshu.com/p/2074f7572694
2. 使用Anyproxy 代理抓包,通过nodejs 设置需要截获的数据
3.详细的使用说明请见官网 https://github.com/alibaba/anyproxy/tree/master/rule_sample 及实例 https://github.com/alibaba/anyproxy/blob/master/docs/cn/src_doc.md
var http = require('http');
var querystring = require('querystring');
module.exports = {
*beforeSendResponse(requestDetail, responseDetail)
{
if (requestDetail.url.indexOf('beta.ihercules.cn') > 0) {
const newRequestOptions = requestDetail.requestOptions;
const newResponse = responseDetail.response;
var req_data = decodeURIComponent(requestDetail.requestData);
var post_data={"responseBody":newResponse.body.toString(),"requestUrl":requestDetail.url,"requestHeaders":newRequestOptions.headers,"requestBody":req_data};
var content=JSON.stringify(post_data);
var server_port
if (requestDetail.url.indexOf('beta.ihercules.cn/message/getMessage') > 0) {
server_port = 8877; //Java 服务
}else{
server_port = 5001; //Python 服务
}
var options = {
host:'127.0.0.1',
path: '/crawl',
port:server_port,
method: 'POST',
headers: {
'Content-Type': 'application/json'
}
};
var req = http.request(options, function(res){
res.setEncoding('utf8');
res.on('data',function(data){
console.log("data:",data);
});
});
req.write(content);
req.end;
}
},
*beforeDealHttpsRequest(requestDetail) {
return true;
}
};
3. windows 启动代理服务,抓取数据 anyproxy -i -p 8001 -w 8002 -r D:\anyproxycrawljs\shop.js
linux 启动 /usr/local/nodejs/node12/bin/anyproxy -i -p 8001 -w 8002 -r /usr/local/nodejs/shop.js
MAC : anyproxy -i -p 8001 -w 8002 -r /Users/heavengifts/Desktop/nodejs/hs.js
ps -ef | grep anyproxy
4. 开发服务端接口。对接数据库接收数据
注意 : 数据库表设计,shopid设置 UNIQUE