Here's another solution:
public String searchAttribute(Element element, String str) { Elements lists = element.select("[id=list]"); for( Element e : lists ) { Elements result = e.select("option:contains(" + str + ")"); if( !result.isEmpty() ) { return result.first().attr("value"); } } return null; }
Test:
Document doc = Jsoup.parse(html); // html is your listed html / xml Strign result = searchAttribute(doc, "Second value") // result = 1
source share