一分钟学会如何自动抓取app数据

网络爬虫比较适合搜集web页面数据,但在app当道的时代,很多app根本就没有对应的web网站,所以使用传统的网络爬虫抓取数据已不再适用。最近研究了一下解决方案,发现目前市面上的解决方案要么是java要么是python,门槛有点高,开发和维护成本比较高。最近一直都在研究的冰狐智能辅助号称可以不用编程就可以实现app自动化,今天我们就用它来试下在不编程的前提下如何轻松实现自动抓取app 数据,下面以拼多多为例进行讲解。

准备工作

  1. 注册冰狐智能辅助账号
  2. 准备android手机一台
  3. 在android手机中安装并登录冰狐智能辅助app

详细准备过程请查看这里icon-default.png?t=M3K6https://aznfz.com/document/prepare一定要严格按照文档提示完成所有步骤,否则可能无法正常工作。

业务逻辑

目标:获取拼多多中价格小于1.6的商品

  1. 启动拼多多
  2. 循环浏览商品列表
  3. 挑选价格小于1.6的商品

具体实现

创建自动构建

在网页端「移动端」/「自动构建脚本」中创建一个名为“test”的自动构建,然后点击“配置构建”。所有的业务相关模块都放在main模块中,点击main模块的“编辑”按钮,如下图所示:

 

选择模块和配置参数

直接根据上面的业务逻辑来选择对应的业务模块,并配置相关参数

1.启动拼多多,选择“启动App”模块,并配置包名和tag名

 2.循环浏览商品列表,循环滚动页面,选择“循环处理”模块,类型选择永久循环类型

 3.遍历当前的商品列表,选择“遍历容器”模块

4.挑选价格小于1.6的商品,选择“获取控件文本”模块提取价格

 

自动构建模块和参数配置

完整的自动构建模块和配置参数如下,可以直接在自动构建处,点击“test”右边的“配置源码”按钮,把如下配置数据粘贴进去即可自动生成自动构建。

{
	"type": "root",
	"children": [{
		"type": "declareVar",
		"var": [{
			"name": "temp",
			"type": "normal",
			"initType": "null",
			"initValue": "null"
		}, {
			"name": "ret",
			"type": "normal",
			"initType": "null",
			"initValue": "null"
		}, {
			"name": "view",
			"type": "normal",
			"initType": "null",
			"initValue": "null"
		}, {
			"name": "viewContainer",
			"type": "normal",
			"initType": "null",
			"initValue": "null"
		}, {
			"name": "tag",
			"type": "normal",
			"initType": "null",
			"initValue": "null"
		}, {
			"name": "item",
			"type": "normal",
			"initType": "null",
			"initValue": "null"
		}, {
			"name": "index",
			"type": "normal",
			"initType": "null",
			"initValue": "null"
		}, {
			"name": "data",
			"type": "normal",
			"initType": "string",
			"initValue": ""
		}, {
			"name": "text",
			"type": "normal",
			"initType": "string",
			"initValue": ""
		}]
	}, {
		"type": "main",
		"desc": "业务逻辑入口",
		"debug": false,
		"params": [],
		"children": [{
			"type": "launchApp",
			"desc": "启动APP",
			"debug": false,
			"packageName": "com.xunmeng.pinduoduo",
			"tag": "txt:推荐|txt:首页#",
			"maxStep": "30",
			"children": [{
				"type": "loop",
				"desc": "循环处理",
				"class": "4",
				"debug": false,
				"children": [{
					"type": "scroll",
					"desc": "滚动处理",
					"class": 1,
					"debug": false,
					"direction": "up",
					"tag": "",
					"family": [],
					"descendant": [],
					"widgetIndex": "0",
					"minDistance": "0.98",
					"maxDistance": "0.98",
					"minScrollCount": "1",
					"maxScrollCount": "1",
					"minDuration": "500",
					"maxDuration": "500",
					"beforeWait": "1000",
					"afterWait": "1000"
				}, {
					"type": "traverse",
					"desc": "遍历当前商品列表容器",
					"class": 1,
					"debug": false,
					"tag": "cn:android.support.v7.widget.RecyclerView#",
					"family": [],
					"descendant": [],
					"failed": "",
					"traverseSelf": false,
					"retryCount": "0",
					"startIndex": "0",
					"lastIndex": "0",
					"randomPickCount": "0",
					"clickable": false,
					"className": "",
					"children": [{
						"type": "searchView",
						"desc": "搜索价格",
						"debug": false,
						"tag": "txt:¥#",
						"root": "item",
						"family": [],
						"failed": "",
						"duration": "500",
						"maxStep": "5",
						"beforeWait": "0",
						"afterWait": "0",
						"fetchResultIndex": "0",
						"returnVarIsLocal": false,
						"children": [{
							"type": "dataDeal",
							"desc": "数据价格控件",
							"debug": false,
							"data": "view",
							"operate": ["0:nextSibling"],
							"returnVarName": "view"
						}, {
							"type": "getText",
							"desc": "获取商品价格",
							"class": "2",
							"debug": false,
							"family": [],
							"descendant": [],
							"returnType": "float",
							"returnVarName": "text",
							"returnVarIsLocal": true,
							"target": "view"
						}, {
							"type": "if",
							"desc": "判断价格是否满足要求",
							"class": "2",
							"debug": false,
							"family": [],
							"descendant": [],
							"expr": "(typeof text == 'number') && (text<=1.6)",
							"children": [{
								"type": "toast",
								"desc": "弹出框",
								"debug": false,
								"textList": ["string-找到价格小于规定的商品了"],
								"x": "-1",
								"y": "-1",
								"duration": "1000",
								"beforeWait": "0",
								"afterWait": "0"
							}]
						}],
						"false": {}
					}]
				}]
			}],
			"false": {}
		}]
	}],
	"desc": "根模块",
	"debug": false
}

运行测试

请按如下步骤运行测试

  1. 开启冰狐智能辅助app调试模式
  2. 把自动构建编译成js脚本,在网页端「移动端」/「自动构建脚本」找到“test”,然后点击右边的“编译”按钮,即可自动生成名 test 的js脚本。
  3. 运行js脚本,在网页端「移动端」/「移动端脚本」找到到“test”,然后点击右边的“运行”按钮,选择设备,开始执行脚本。

  • 32
    点赞
  • 59
    收藏
    觉得还不错? 一键收藏
  • 12
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值