简体   繁体   中英

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

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();

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");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM