Search code examples
androidjsoup

Getting audio URL from jsoup android


Below is the HTML tag for the audio link url,

enter image description here

And below is the logic I used to get the URL,

String url = "https://www.dictionary.com/browse/happy?s=t";
                  
Document doc = Jsoup.connect(url).get();

 Elements wordBlock = doc.getElementsByClass("e16867sm0");
 Element e = wordBlock.get(0);
                      
 Elements audioSection = e.getElementsByClass("e1rg2mtf7");
 String audioUrl = audioSection.get(0).attr("audio");

But still I am unable to get the URL,

How can we get the URL of audio by using class id.


Solution

  • You can use either doc.select("source[type=audio/ogg]" for the first file or doc.select("source[type=audio/mpeg]" for the second one.
    You can also use source[type^=audio] - it will give you both.