Think_Twice
Think_Twice

Reputation: 323

How to use JSOUP to get the data from website

I want to get the 'Fixtures' data from this page: [Link] using jsoup but I have no clue of how to get the data.

Upvotes: 0

Views: 91

Answers (1)

Simon
Simon

Reputation: 1737

  1. Include Jsoup in gradle

    implementation "org.jsoup:jsoup:1.11.3"
    
  2. Connect to page

    Document doc = Jsoup.connect('url').get();
    
  3. Select and get the element by id or xpath...

    Elements el  = doc.getElementsByClass("col");
        for (int i = 0; i < el.size(); i++) {
            if (el.get(i).classNames().contains("col1")) {
                Log.d("EL", el.html());
            }
            if (el.get(i).classNames().contains("col2")) {
                Log.d("EL", el.html());
            }
            if (el.get(i).classNames().contains("col3")) {
                Log.d("EL", el.html());
            }
        }
    

p.s. You will need to handle asnyc call yourself Jsoup.connect will throw NetworkOnMainThreadException if you call it directly in activity.

Upvotes: 1

Related Questions