Jsoup解析很慢

时间:2018-04-01 06:43:30

标签: java android jsoup

在Intellij IDEA(或Eclipse)中解析大约10秒。很酷。 但是当我在Android工作室采用相同的代码时,大约需要5分钟。非常慢.... 我做错了什么?我该如何改进呢?

public void run(){

            Document docMake;
            Document docModel;
            try {
                docMake = Jsoup
                        .connect("https://av.by/")
                        .get();

                Element selectMake = docMake
                        .select("option:containsOwn(Марка автомобиля)")
                        .get(0);
                Elements makes = selectMake.siblingElements();

                List<MakeCarRealm> listMakes = new ArrayList<>();
                MakeCarRealm makeCarRealm;

                for (Element make : makes) {

                    makeCarRealm = new MakeCarRealm(make.text(), Integer.valueOf(make.attr("value")));
                    List<ModelRealm> listModels = new ArrayList<>();

                    docModel = Jsoup
                            .connect("https://cars.av.by/search?brand_id%5B%5D=" + make.attr("value") + "&model_id%5B%5D=0&year_from=&year_to=&currency=USD&price_from=&price_to=")
                            .get();

                    Element selectModel = docModel
                            .select("option:containsOwn(Модель)")
                            .get(0);
                    Elements models = selectModel.siblingElements();

                    for (Element model : models) {
                        ModelRealm modelRealm = new ModelRealm(model.text(), Integer.valueOf(model.attr("value")));
                        listModels.add(modelRealm);
                    }
                    makeCarRealm.setModelsCarsR(listModels);
                    listMakes.add(makeCarRealm);
                }
                ChooseCarsRealm carsRealm = new ChooseCarsRealm(listMakes);
            } catch (IOException e) {
                e.printStackTrace();
            }

        }

0 个答案:

没有答案