1

I'm trying parse html with Jsoup lib. Everything works perfect, but something that does't display.
Code:

protected ArrayList<Order> doInBackground(String... urls) {

        listItems.clear();
        myAdapterDouble.notifyDataSetChanged(); 
        String url = null;

        try {
            Document doc = Jsoup.connect(URL).timeout(0).userAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6").get();

            Elements days = doc.select("div.day_now");
            for (Element day : days) {
                dd = day.select("div.tooltip");
                for (Element d : dd) {

                    title = d.select("td.tooltip_title h4").text();
                    time = d.select("td.tooltip_info h4").text();
                    img = d.select("td.tooltip_desc img[src]");

                    Order o = new Order();
                    o.setLink(URL + img.attr("src"));
                    o.setTextName(title);
                    o.setTextTime(time
                            .replace("on", getResources().getString(R.string.on))
                            .replace("at", getResources().getString(R.string.at))
                            .replace("Ep:", getResources().getString(R.string.episode))
                            .replace("Final", getResources().getString(R.string.final_ep)));
                    o.setDetailsUrl(URL + url);   //set urls text in list
                    listItems.add(o);
                }

                Elements links = day.select("h3");
                for (Element link : links) {
                    url = link.select("a").attr("href");  // parse page urls
                    System.out.println(url);    //display urls in LogCat                    
                }
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
        return listItems;
    }

In LogCat i see urls, that i parse in code above

01-20 12:13:17.671: I/System.out(23390): /show/678/AKB0048_next_stage
01-20 12:13:17.671: I/System.out(23390): /show/668/Battle_Spirits%3A_Sword_Eyes
01-20 12:13:17.671: I/System.out(23390): /show/694/Beast_Saga
01-20 12:13:17.671: I/System.out(23390): /show/660/Cross_Fight_B-Daman_eS

But these links are not displayed on the screen instead i get null.
What am I doing wrong?
Thanks.

1 Answer 1

1

Currently you are not adding url to listItems . change your code as to get url :

           ArrayList<Order> newarraylist=new ArrayList<Order>; 
           Elements links = day.select("h3");
           int urlcount=0;
           for (Element link : links) {
                url = link.select("a").attr("href");  // parse page urls
                System.out.println(url);    //display urls in LogCat 
              if(urlcount < listItems.size()){
                Order o = (Order)listItems.get(urlcount);
                o.setDetailsUrl(URL + url);   //set urls text in list
                newarraylist.add(o);
              }
              urlcount++;
            }

now return newarraylist from doInBackground instead of listItems

Sign up to request clarification or add additional context in comments.

4 Comments

Not work, urls not displayed. Work rhis Elements links = day.select("h3"); for (Element link : links) { url = link.select("a").attr("href"); System.out.println(url); int i = 0; if (i < listItems.size()) { Order o = (Order)listItems.get(i); o.setDetailsUrl(URL + url); newarraylist.add(o); } } but is it wrong code that displayed only last url to first item of list
@Azat-777 : try it this will work and what do u mean by "it is not work" i last comment u have say that it's working now you are saying it's not working . i have indicated why u are not getting url in ArrayList as according to your question and my code is just suggestion not perfect copy paste . Thanks
Thanks for your help. url = link.select("a").attr("href"); // i get urls, but in this place o.setDetailsUrl(URL + url); //no urls. P.S.: Problem done. You or i mixed up the character ">"
@Azat-777 : you can try it another way first extract urls in separate arraylist then add it to listItems arraylist .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.