Sorting objects in arraylist depending on how they appear on a website?

时间:2019-04-17 02:20:37

标签: java android html sorting

I'm fetching data over a page using Jsoup and I want to stock text and images in the format they appear on the website. I'm able to get the text and images but how can I sort them in my ArrayList so they can match the webpage?

private String downloadHtml(String urlPath) {
    try {
        Document doc = Jsoup.connect(urlPath).get();
        String title = doc.getElementsByClass("entry-title").get(0).text();

        Elements pContent = doc.select("div.entry-content > p");
        Elements imgUrls = doc.select("div.entry-content > p > img");

        for (Element textContent : pContent) {
            String text = textContent.text();
            listFocused.add(text);
        }

        for (Element imgUrl : imgUrls ) {
            String imgLink = imgUrl.absUrl(("src"));
            listFocused.add(imgLink);
        }

        for(String output : listFocused) {
            Log.d(TAG, "ArrayList: " + output + "\n");
        }
        return null;

    } catch (MalformedURLException e) {
        Log.e(TAG, "downloadHTML: Invalid Url " + e.getMessage());
    } catch (IOException e) {
        Log.e(TAG, "downloadHTML: IO Exception reading data: " + e.getMessage());
    } catch (SecurityException e) {
        Log.e(TAG, "downloadHTML: Security Exception. Need permission? " + e.getMessage());
    }

    return null;
}

0 个答案:

没有答案