JSoup not able to get links from html

  android, android-studio, java, jsoup

I’m trying to get links from html of a site but unable to do so using Jsoup.

This is the HTML:

<div class="anime_muti_link">
    <ul>
  <li><div class="doamin">Domain</div><div class="link">Link</div></li>
  <li class="anime">
    <a href="#" class="active" rel="1" data-video="example.com" ><div class="server m1">Server m1</div><span>Watch This Link</span></a>
  </li>
    
  <li class="anime">
    <a href="#" rel="1" data-video="example.com" ><div class="server m1">Server m2</div><span>Watch This Link</span></a>
  </li>
  
              <li class="xstreamcdn">
      <a href="#" rel="29" data-video="example.com">Xstreamcdn</div><span>Watch This Link</span></a>
    </li>
          <li class="mixdrop">
      <a href="#" rel="7" data-video="example.com"><div class="server mixdrop">Mixdrop</div><span>Watch This Link</span></a>
    </li>
          <li class="streamsb">
      <a href="#" rel="13" data-video="example.com">StreamSB</div><span>Watch This Link</span></a>
    </li>
          <li class="doodstream">
      <a href="#" rel="14" data-video="example.com">Doodstream</div><span>Watch This Link</span></a>
    </li>
  
</ul>
</div>

This is the android code that I wrote which doesn’t seem to work:

try {
                Document doc = Jsoup.connect(URL).get();
                Elements content = doc.getElementsByClass("anime_muti_link");
                Elements links = content.select("a");

                String[] urls = new String[links.size()];
                for (int i = 0; i < links.size(); i++) {
                    urls[i] = links.get(i).attr("data-video");
                    if (!urls[i].startsWith("https://")) {
                        urls[i] = "https:" + urls[i];
                    }
                }
                arrayList.addAll(Arrays.asList(urls));
                Log.d("CALLING_URL", "Links: " + Arrays.toString(urls));

            } catch (IOException e) {
                e.getMessage();
            }

Can someone please help me with this? Thanks

Edit: Basically I’m trying to get those 6 links and add them to my list to use it within the app.

Source: Android Questions

LEAVE A COMMENT