How to change this javascript Code for JSOUP library in Android?

Viewed 23

I have written and tested this code in console Window of chrome and it is giving me the desired result. But I want this same code for JSOUP in android. Please tell me how to do it. I tried to do some modification and change it to be used in android, but I did not succeed.

This is the javascript code

document.querySelector('ul').getElementsByTagName('img')[2].getAttribute('alt')

And this was my modified code which did not worked.

Document doc = Jsoup.connect(url).get();
doc.select("ul").tagName("img").get(2).getElementsByAttribute("alt").text();
1 Answers

You are trying to get the whole element by attribute instead of taking the attribute of an element. Proper way to take alt text would be

doc.select("ul").tagName("img").get(2).attr("alt");
Related