二、工具介绍
官网: http://anyproxy.io/cn/
Git: https://github.com/alibaba/anyproxy
Appiums是一款自动化Mobile测试工具,我们可以用来写手机端的自动化脚本(比如自动抢红包)
官网: http://appium.io/
用于模拟Android手机,当然还有其他模拟器(夜神模拟器,Android vitural Device Manager的模拟器),使用上还是MuMu的速度快点。
官网: http://mumu.163.com/
三、结构
需要编码的地方
Appium自动化脚本
- 找到公众号
- 点击第一篇文章
Anyproxy rule.js
- 重定向到旧版的公众号历史列表(新版的历史获取不到)
- 保存第一页的数据,添加js scrollTo 脚本 返回给微信客户端(为了自动向下分页,动作慢点,要不会被禁止访问一段时间)。
- 持续保存其他页数据。(列表中的标题和文章URL就获取了,文章内容可以通过URL直接去Get数据,就不在这里操作了)
其他都是服务搭建了。
四、遇到的问题模拟器相关
- 需要电脑VT虚拟化(不支持就换台吧)
- 如果运行模拟器时出现蓝屏,用管理员运行Powershell 执行
bcdedit /set hypervisorlaunchtype off
Appiums Server相关
- 模拟器刚开机的时候需要adb连接下
# 可以使用下面命令,查看adb程序是否有连接设备 adb devices # 没有的话需要执行下这个命令(ip和port是 模拟器的 ip 和 port) # 不知道是多少?我也是根据模拟器google的 adb connect 127.0.0.1:7555
Anyproxy rule.js 相关(我的版本是4.1.0)
- 查找对应的 request 很麻烦,我直接贴下 beforeSendResponse 的代码,可以参考下。
beforeSendResponse: function (requestDetail, responseDetail) { if (/s\?__biz/i.test(requestDetail.url) || /mp\/rumor/i.test(requestDetail.url)) { var parsedUrl = url.parse(requestDetail.url, true); var biz = parsedUrl.query['__biz']; // 修改 response 转发到 微信客户端. (重定向到旧列表页面) var href = "http://mp.weixin.qq.com/mp/getmasssendmsg?__biz=" biz "#wechat_webview_type=1&wechat_redirect"; const newResponse = responseDetail.response; newResponse.statusCode = 302; newResponse.header['Location'] = href return newResponse } else if (/mp\/profile_ext\?action=home/i.test(requestDetail.url)) { // 第一页的列表数据,会发现和下一页结构不大一样 try { var body = untils.byteToString(responseDetail.response.body) var reg = /var msgList = \'(.*?)\';/; var ret = reg.exec(body); // 保存到rabitmq,根据自己需要替换存储位置 mqClient.sent(config.queue, ret[1].replace(/"/g, '"')) // 自动向下翻页js 代码,别太快,会封号!!!!!!! body = "<script type='text/javascript'>setInterval(function(){window.scrollTo(0,document.body.scrollHeight);},5000)</script>"; // 修改 response 转发到 微信客户端 responseDetail.response.body = body return responseDetail.response } catch (e) { console.log(e) } } else if (/mp\/profile_ext\?action=getmsg/i.test(requestDetail.url)) { // 第n(n!=1)页的列表数据 var json = JSON.parse(untils.byteToString(responseDetail.response.body)) // 保存到rabitmq,根据自己需要替换存储位置 mqClient.sent(config.queue, json['general_msg_list']) } },



















