刘小帅

jdDemo
var shopName = ""; //商品名称 var versionName = get...
扫描右侧二维码阅读全文
11
2021/05

jdDemo

var shopName = ""; //商品名称
var versionName = getPackageVersion(app.getPackageName("京东到家"));//版本名称
var shopNum = "" //商品个数

//获取版本号
function getPackageVersion(packageName) {
    importPackage(android.content);
    var pckMan = context.getPackageManager();
    var packageInfo = pckMan.getPackageInfo(packageName, 0);
    return packageInfo.versionName;
};
function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "-";
    var seperator2 = ":";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
            + " " + date.getHours() + seperator2 + date.getMinutes()
            + seperator2 + date.getSeconds();
    return currentdate;
}



files.append("/sdcard/jdDemo.xls","\uFEFF" + "标题" + "," + "原价" + "," + "现价" + "," + "促销活动" + "," + "门店" + "," + "参评人数 " + "," + "参评结果" + "," + "查询时间" + "," + "\n");

launchApp("京东到家");
sleep(5000);
while(true){
    if(!text("发现").exists() && !text("购物车").exists() && !text("我的").exists()){
        back();
        sleep(1000);
    }else{
        break;
    }
}



id("com.jingdong.pdj:id/home_header_search_ll").findOne().click();
sleep(1000);
setText(shopName);
sleep(1000);
text("搜索").findOne().click();
sleep(5000);

if(versionName == "8.8.0") {
    var num = 0;
    label1:
    while (true){
        var searchList = id("com.jingdong.pdj:id/view_columns").find();
        var seLen = searchList.length - 1;
        for (i = 0; i < searchList.length; i++) {
            if (last == searchList[i].findOne(id("com.jingdong.pdj:id/sku_name_view")).text()) {
                continue;
            }
            searchList[i].parent().click();
            sleep(2500);

            // 获取价格
            var price = id("com.jingdong.pdj.plunginnewstore.feature:id/aw").find()[0].findOne(id("com.jingdong.pdj.plunginnewstore.feature:id/b0"))
        
            var priceC = price.childCount();

            if (id("com.jingdong.pdj.plunginnewstore.feature:id/aw").find()[0].findOne(textMatches("券后*"))) {
                //进入详细页面
                var shopListOne = id("com.jingdong.pdj.plunginnewstore.feature:id/ax").find();
                shopListOne.click(); 
                sleep(1500);
                var nowPrice = id("com.jingdong.pdj:id/tv_price").findOne().text();
                var prePrice = id("com.jingdong.pdj.plungindetail.feature:id/fv").findOne().text();
                back();
                sleep(700)
            }

            if (priceC == 1 && !id("com.jingdong.pdj.plunginnewstore.feature:id/aw").find()[0].findOne(textMatches("券后*"))){
                var nowPrice = price.child(0).child(0).child(0).text()
                var prePrice = "";
            }else if ( priceC == 2 && !id("com.jingdong.pdj.plunginnewstore.feature:id/aw").find()[0].findOne(textMatches("券后*"))){
                var nowPrice = price.child(0).child(0).child(0).text()
                var prePrice = price.child(1).child(0).child(0).text()
            }    
            //门店
            var supermarket = id("com.jingdong.pdj.plunginnewstore.feature:id/f4").findOne(3000).text()
            //点击进入商品详细页面
            var shopListOne = id("com.jingdong.pdj.plunginnewstore.feature:id/ax").find();
            shopListOne.click();
            sleep(1500);
            // 促销活动
            var activeResult = "" 
            if (text("促销").exists()){
                active = Number(id("com.jingdong.pdj.plungindetail.feature:id/de").findOne().child(0).child(0).childCount());
                for(j = 0;j < active;j ++ ){
                activeResult += id("com.jingdong.pdj.plungindetail.feature:id/de").findOne().child(0).child(0).child(j).text();
                }
            
            }
                
            //获取标题
            var shopTitle = id("com.jingdong.pdj.plungindetail.feature:id/x").findOne().text();
            
            //评价人数
            var evonNum = ""
            if (textMatches("(共[0-9]{1,10}人评价)").exists()){
                var evonNum = textMatches("(共[0-9]{1,10}人评价)").findOne(3000).text().toString();
                evonNum = evonNum.slice(1,-1)
            }

                        
            //评价结果
            var evResult = ""
            if (id("com.jingdong.pdj.plungindetail.feature:id/c9").exists()){
                var evResult = id("com.jingdong.pdj.plungindetail.feature:id/c9").findOne().child(1).text()
            }
            
            if (evonNum == ""){
                var evResult = "100%";
            }
            var workTime = getNowFormatDate();

            if (prePrice == " undefined") {
                var  prePrice = "";
            }
            // log("标题: " + shopTitle + "," + "原价: " + prePrice + "," + "现价:" + nowPrice + "," + "促销活动: " + activeResult + "," + "门店: " + supermarket + "," + "参评人数: " + evonNum + "," + "参评结果: " + evResult + "," + "查询时间: " + workTime + "\n");
            files.append("/sdcard/jdDemo.xls","\uFEFF" + shopTitle + ","  + prePrice + ","  + nowPrice + ","  + activeResult + "," + supermarket + ","  + evonNum + "," + evResult + ","  + workTime + "\n");
            back();
            sleep(1000)
            back();
            sleep(1000)
            num += 1;
            if (num == shopNum){
                break label1;
            }
        }
        var last = searchList[seLen].findOne(id("com.jingdong.pdj:id/sku_name_view")).text();
        sleep(100);
        id("com.jingdong.pdj.plunginsearchall.feature:id/ba").findOne().scrollForward();
        sleep(1500);
    }

}else if (versionName = "8.8.5"){
    var num = 0;
    label1:
    while (true){
        var searchList = id("com.jingdong.pdj:id/view_columns").find();
        var seLen = searchList.length - 1;
        for (i = 0; i < searchList.length; i++) {
            if (last == searchList[i].findOne(id("com.jingdong.pdj:id/sku_name_view")).text()) {
                continue;
            }
            
            searchList[i].parent().click();
            sleep(2500);
            // 获取价格
            var price = id("com.jingdong.pdj.plunginnewstore.feature:id/good_price_view").find()[0]
            var priceC = price.childCount();
            sleep(1500);

            if (priceC == 1 ){
                var nowPrice =  id("com.jingdong.pdj.plunginnewstore.feature:id/good_price_view").findOne().child(0).child(0).child(0).text();
                var prePrice = "";
            }else if ( priceC == 2 ){
                var nowPrice =  id("com.jingdong.pdj.plunginnewstore.feature:id/good_price_view").findOne().child(0).child(0).child(0).text();
                var prePrice =  id("com.jingdong.pdj.plunginnewstore.feature:id/good_price_view").findOne().child(1).child(0).child(0).text();
            }    
            //门店
            var supermarket = id("com.jingdong.pdj.plunginnewstore.feature:id/store_header_title").findOne(3000).text()
            //点击进入商品详细页面
            var shopListOne = id("com.jingdong.pdj.plunginnewstore.feature:id/good_item_view").find()[0];
            shopListOne.click(); 
            sleep(1500);
            // 促销活动
            var activeResult = "" 
            if (text("促销").exists()){
                active = Number(id("com.jingdong.pdj.plungindetail.feature:id/layout_tag_list").findOne(3000).child(0).child(0).childCount());
                for(j = 0;j < active;j ++ ){
                activeResult += id("com.jingdong.pdj.plungindetail.feature:id/layout_tag_list").findOne(3000).child(0).child(0).child(j).text();
                }
            
            }
                
            //获取标题
            var shopTitle = id("com.jingdong.pdj.plungindetail.feature:id/commodity_detail_name").findOne(3000).text();
            
            //评价人数
            var evonNum = ""
            if (textMatches("(共[0-9]{1,10}人评价)").exists()){
                var evonNum = textMatches("(共[0-9]{1,10}人评价)").findOne(3000).text().toString();
                evonNum = evonNum.slice(1,-1)
            }

                        
            //评价结果
            var evResult = ""
            if (id("com.jingdong.pdj.plungindetail.feature:id/layout_comment_label").exists()){
                var evResult = id("com.jingdong.pdj.plungindetail.feature:id/layout_comment_label").findOne().child(1).text()
            }
            
            if (evonNum == ""){
                var evResult = "100%";
            }
            var workTime = getNowFormatDate();

            if (prePrice == " undefined") {
                var  prePrice = "";
            }
            // log("标题: " + shopTitle + "," + "原价: " + prePrice + "," + "现价:" + nowPrice + "," + "促销活动: " + activeResult + "," + "门店: " + supermarket + "," + "参评人数: " + evonNum + "," + "参评结果: " + evResult + "," + "查询时间: " + workTime + "\n");
            files.append("/sdcard/jdDemo.xls","\uFEFF" + shopTitle + ","  + prePrice + ","  + nowPrice + ","  + activeResult + "," + supermarket + ","  + evonNum + "," + evResult + ","  + workTime + "\n");
            back();
            sleep(1000)
            back();
            sleep(1000)
            num += 1;
            if (num == shopNum){
                break label1;
            }
        }
        var last = searchList[seLen].findOne(id("com.jingdong.pdj:id/sku_name_view")).text();
        sleep(100);
        id("com.jingdong.pdj.plunginsearchall.feature:id/recyclerview").findOne(3000).scrollForward();
        sleep(1500);
    }
}
Last modification:May 20th, 2021 at 03:58 pm
If you think my article is useful to you, please feel free to appreciate

Leave a Comment