刘小帅

mt
var supermarket = "家乐福(北京望京店)"; // var superma...
扫描右侧二维码阅读全文
08
2021/05

mt


var supermarket = "家乐福(北京望京店)";
// var supermarket = "佳美连锁超市(望京店)"
var searchPre = "防疫小站"; //希望从哪个一级标题开始抓 缺省为从第一个标题开始

//起始一级标题函数
function jumping(searchPre){
    if (!searchPre == ""){
        while(true){
            sleep(1);
            if(id("com.sankuai.meituan:id/txt_category_name_1").text(searchPre).exists()){
                id("com.sankuai.meituan:id/txt_category_name_1").text(searchPre).findOne().parent().parent().parent().click();
                sleep(1000);
                break;
            }else{
                id("com.sankuai.meituan:id/poi_dish_categories").findOne().scrollForward();
                sleep(200)
            }
        }
        //如果没有设置默认从第一个一级标题开始抓
    }else{
        id("com.sankuai.meituan:id/layout_tag_category").find()[2].parent().click();
        sleep(1000);
        id("com.sankuai.meituan:id/layout_tag_category").find()[0].parent().click();
        sleep(1000);
    }

}

//截图权限自动确认
// threads.start(function () {
//     var beginBtn;
//        if (beginBtn = classNameContains("Button").textContains("立即开始").findOne(2000)) {
//            beginBtn.click();
//            sleep(1000);
//        }
//    });

// 获取一级分类
function child(){
    var tiao = id("com.sankuai.meituan:id/category_item_indicator_left").findOne();
    var oneClass = tiao.parent().child(0).child(0).child(0).text();
    if (oneClass == ""){
        var oneClass = tiao.parent().child(0).child(0).child(1).text();
    }else{
        var oneClass = tiao.parent().child(0).child(0).child(0).text();   
    }
        
    return oneClass;
}

// requestScreenCapture();
// sleep(500);

//获取当前二级分类函数 暂时无用
function twoChildResult(){
    // requestScreenCapture();
    // while(true){
    //     sleep(1);
        var twoChild = id("com.sankuai.meituan:id/takeout_txt_tab").find()
        for (i = 0; i < twoChild.length; i++) {
            var boundResult = twoChild[i].bounds();
            var x = boundResult.centerX();
            var y = boundResult.centerY();
            //颜色对比
            var img = captureScreen();
            sleep(2000);
            var color = images.pixel(img,x,y);
            sleep(300);
            var result = colors.toString(color);
            sleep(300);
            if (result == "#ffffedc0") {
                return twoChild[i].text();
            }
        }
        // var status = id("com.sankuai.meituan:id/tab_lv").scrollForward();
        // sleep(2000);
        // if (status == true) {
        //     toastLog("当前为某个一级分类中的最后一个二级分类");
        //     sleep(1000);
        //     break;
        // }
    //     break;
    // }

}


function app(){
    //标题 销量 价格 分类
    var shopList = id("com.sankuai.meituan:id/detail_content_layout").find();
    var shopLen = shopList.length;
    var last = shopList[shopLen -1].child(0).text();//最后一个元素 为了防止滑动元素重复

    for (i = 0;i < shopLen; i++){
        var shopTitle = shopList[i].child(0).text();
        if (shopTitle != last) {
            var price = shopList[i].child(4).child(1).text();
            var sales = shopList[i].child(2).child(0).text();
        
            //如果存在优惠信息
            if (shopList[i].child(3).child(0)){
                var pre = shopList[i].child(3).child(0).text()
                log("一级分类: " + child()  +  ",标题: " + shopTitle  + ",销量: " + sales  + ",价格: " + price + ",优惠信息: " + pre + ",\n");
                files.append("/sdcard/"+supermarket+".txt","一级分类: " + child()  +  ",标题: " + shopTitle  + ",销量: " + sales  + ",价格: " + price + ",优惠信息: " + pre + ",\n")
    
            }else{
                log("一级分类: " + child()  +  ",标题: " + shopTitle  + ",销量: " + sales  + ",价格: " + price + ",\n");
                files.append("/sdcard/"+supermarket+".txt","一级分类: " + child()  +  ",标题: " + shopTitle  + ",销量: " + sales  + ",价格: " + price + ",\n");
            }
            
        }

    }
}


//拉App
launchApp("美团");
sleep(5000);
while(true){
    sleep(1);
    if(!desc("消息").exists() && !desc("我的").exists() && !desc("电商").exists()) {
        back();
        sleep(1000);
    }else{
        break
    }
}


//点超市便利店
while(true){
    sleep(1);
    if(!desc("超市/便利店").exists()){
        className("android.support.v4.view.ViewPager").find()[0].scrollForward();
        sleep(300);
        className("android.support.v4.view.ViewPager").find()[0].scrollForward();
        sleep(300);
    }else{
        break;
    }
}

desc("超市/便利店").findOne().click();
sleep(1000);
//点搜索框
id("com.sankuai.meituan:id/animte_action_search").findOne().click();
sleep(700);
//输入超市名
setText(supermarket);
sleep(300);
//点搜索
text("搜索").findOne().click();
sleep(2000);
//点击搜索的结果 (进入超市)
text(supermarket).find()[1].parent().parent().parent().parent().click();
sleep(2000);
//如果另一种布局方式
if (text("全部分类").exists()){
    text("全部分类").findOne().parent().click();
    sleep(3000);
}

//因右侧显示商品太少 点击两次会好一些
jumping(searchPre); 

while(true){

    app();
    // 滑动完发现新分类 并且新分类不等于当前分类 则点击新分类
    var scrollTitle = id("com.sankuai.meituan:id/txt_category_name").findOne(500);
    if(id("com.sankuai.meituan:id/txt_category_name").exists() && scrollTitle.text() != child() ){
        app();
        //点击新分类
        id("com.sankuai.meituan:id/txt_category_name_1").text(scrollTitle.text()).findOne().parent().parent().parent().click();
        sleep(500);
        app();
    }
    //滑动
    var scroStatus = id("com.sankuai.meituan:id/recycler").findOne().scrollForward();
    sleep(500);
    if (scroStatus == false) {
        var lastTitle = id("com.sankuai.meituan:id/txt_category_name_1").find();
        var lastTiLen = lastTitle.length;
        lastTitle[lastTiLen -1].parent().parent().parent().click();
        sleep(500);
        var shopList = id("com.sankuai.meituan:id/detail_content_layout").find();
        var shopLen = shopList.length;
        var shopTitle = shopList[shopLen - 1].child(0).text();
        var price = shopList[shopLen - 1].child(4).child(1).text();
        var sales = shopList[shopLen - 1].child(2).child(0).text();
        if (shopList[shopLen - 1].child(3).child(0)){
            var pre = shopList[shopLen - 1].child(3).child(0).text()
            log("一级分类: " + child()  +  ",标题: " + shopTitle  + ",销量: " + sales  + ",价格: " + price + ",优惠信息: " + pre + ",\n");
            files.append("/sdcard/"+supermarket+".txt","一级分类: " + child()  +  ",标题: " + shopTitle  + ",销量: " + sales  + ",价格: " + price + ",优惠信息: " + pre + ",\n")

        }else{
            log("一级分类: " + child()  +  ",标题: " + shopTitle  + ",销量: " + sales  + ",价格: " + price + ",\n");
            files.append("/sdcard/"+supermarket+".txt","一级分类: " + child()  +  ",标题: " + shopTitle  + ",销量: " + sales  + ",价格: " + price + ",\n");
        }
        
        toastLog("运行完毕...");
        sleep(200);
        break;
    }

}   


// var shopTitle = (id("com.sankuai.meituan:id/txt_stickyfoodList_adapter_food_name").find());
Last modification:May 10th, 2021 at 09:21 am
If you think my article is useful to you, please feel free to appreciate

Leave a Comment