星空软件

 找回密码
 立即注册

[个人经验] 分享一款拼多多店铺名称和连接提取工具,autojs的,全适配

ydiruxyga | 2024-1-15 15:42:16 | 显示全部楼层 |阅读模式
  1. // 初始延迟10秒
  2. sleep(10000);

  3. // 循环次数设定为20次
  4. for (var loop = 0; loop < 99999999; loop++) {
  5.     var lastElementX, lastElementY;

  6.     // 获取所有TextView控件
  7.     var allTextViews = className("android.widget.TextView").find();

  8.     // 遍历所有TextView控件,判断是否在屏幕可见范围内且包含"已拼"
  9.     for (var i = 0; i < allTextViews.length; i++) {
  10.         var currentTextView = allTextViews[i];
  11.         if (currentTextView.text().indexOf("已拼") !== -1 && isVisible(currentTextView)) {
  12.             var bounds = currentTextView.bounds();
  13.             console.log("找到可见的'已拼'元素: " + currentTextView.text());
  14.             click(bounds.centerX(), bounds.centerY());
  15.             sleep(1600);

  16.             lastElementX = bounds.centerX();
  17.             lastElementY = bounds.centerY();

  18.             // 寻找并点击包含'店铺'的TextView
  19.             var shopTextView = text("店铺").visibleToUser().findOne(1000);
  20.             if (shopTextView != null) {
  21.                 var shopBounds = shopTextView.bounds();
  22.                 console.log("找到'店铺'元素: " + shopTextView.text());
  23.                 click(shopBounds.centerX(), shopBounds.centerY());
  24.                 sleep(1600);

  25.                 // 寻找并点击包含'全部商品'的TextView
  26.                 var allProductsTextView = text("全部商品").visibleToUser().findOne(1000);
  27.                 if (allProductsTextView != null) {
  28.                     var allProductsBounds = allProductsTextView.bounds();
  29.                     console.log("找到'全部商品'元素: " + allProductsTextView.text());
  30.                     click(allProductsBounds.centerX(), allProductsBounds.centerY());
  31.                     sleep(1600);

  32.                     // 在这里加入新的代码





  33. //获取店名字


  34. function 获取所有控件的文本() {
  35.     var 控件文本 = [];
  36.     var 所有控件 = find();

  37.     所有控件.forEach(function(控件) {
  38.         if(控件.text()) {
  39.             控件文本.push(控件.text());
  40.         }
  41.     });

  42.     return 控件文本;
  43. }

  44. var 控件文本 = 获取所有控件的文本();
  45. console.log("所有控件的文本: ", 控件文本);
  46. var 最终变量="所有控件的文本:"+控件文本

  47. var originalText =最终变量
  48.    
  49. var originalText =最终变量

  50. // 先移除 "所有控件的文本:" 部分
  51. var contentText = originalText.replace("所有控件的文本:", "");

  52. // 使用逗号分割内容
  53. var items = contentText.split(',');

  54. // 根据是否包含关键字“满”选择提取的文本
  55. var extractedText;
  56. if (items[0].includes("满") && items.length > 1) {
  57.     extractedText = items[1]; // 如果第一个元素包含“满”且存在第二个元素,则选择第二个元素
  58. } else {
  59.     extractedText = items[0]; // 否则,选择第一个元素
  60. }

  61. console.log(extractedText);
  62. setClip(extractedText);

  63. // 要追加的内容
  64. var contentToAdd = extractedText

  65. // 文件路径
  66. var filePath = "/storage/emulated/0/拼多多/pd.txt";

  67. // 打开文件,准备追加内容
  68. var file = open(filePath, "a"); // 'a' 模式表示追加(append)

  69. // 检查文件是否成功打开
  70. if (file) {
  71.     // 向文件追加内容,并添加换行符
  72.     file.writeline(contentToAdd);

  73.     // 关闭文件
  74.     file.close();
  75. } else {
  76.     // 文件打开失败的处理
  77.     console.log("无法打开文件:" + filePath);
  78. }


  79. back()
  80. sleep(1600);
  81. back()
  82. sleep(1600);

  83. //获取店名字





  84.                     // 这里加入新的代码结束

  85.                 } else {
  86.                     console.log("未找到'全部商品'元素");
  87.                 }

  88.                 // 寻找并点击描述为'分享'的控件
  89.                 var shareDesc = id("pdd").className("android.widget.ImageView").desc("分享").findOne(1000);
  90.                
  91.             } else {
  92.                 console.log("未找到'店铺'元素");
  93.             }
  94.         } else {
  95.             console.log("元素不可见或不包含'已拼': " + currentTextView.text());
  96.         }
  97.     }

  98.     // 从保存的坐标滑动到屏幕顶部
  99.     if (lastElementX !== undefined && lastElementY !== undefined) {
  100.         sleep(1600);
  101.         swipe(lastElementX, lastElementY-100, lastElementX, 0, 1600);
  102.         sleep(1600);
  103.     } else {
  104.        // swipe(device.width / 2, device.height / 2, device.width / 2, 0, 1600);
  105.         sleep(1600);
  106.     }
  107. }

  108. // 隐藏控制台
  109. setTimeout(function() {
  110.     console.hide();
  111. }, 5000);

  112. // 判断元素是否对用户可见
  113. function isVisible(element) {
  114.     var bounds = element.bounds();
  115.     var screenBounds = { left: 0, top: 0, right: device.width, bottom: device.height };
  116.     return bounds.left < screenBounds.right && bounds.right > screenBounds.left &&
  117.            bounds.top < screenBounds.bottom && bounds.bottom > screenBounds.top;
  118. }
复制代码
我用的是autojs pro8.0测试的 需要无障碍




上一篇:autojs检测判断是否开启无障碍,如果没开启就自动跳转开启
下一篇:autojs怎么找控件更准确,分享一些我个人的经验
回复

使用道具 举报

MariquilaJ | 2024-1-15 15:42:30 | 显示全部楼层
感谢大佬分享
回复

使用道具 举报

星辰大海 | 2024-1-15 15:42:33 | 显示全部楼层
感谢
回复

使用道具 举报

rashpell | 2024-1-15 15:42:36 | 显示全部楼层
谢谢分享
回复

使用道具 举报

Gwy | 2024-1-15 15:42:38 | 显示全部楼层
好用
回复

使用道具 举报

avicsahna | 2024-1-15 15:42:42 | 显示全部楼层
支持星空
回复

使用道具 举报

512161614 | 2024-1-15 15:42:45 | 显示全部楼层
666
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

全站声明【必看】|小黑屋|新库软件 |网站地图

GMT+8, 2024-5-19 05:30 , Processed in 0.064110 second(s), 26 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.