I have some html code like this:
<div class="post-text" itemprop="text"><a href="something.com">sometext for example</a></div>
I'm searching sometext word using jsoup and I want it's tag name. For above example it will be a href
. Can anyone help me?
Try this CSS selector:
*:containsOwn(sometext)
http://try.jsoup.org/~1FKtzLpHQFii4u8FFyUuh3GgdPI
String html = "<div class=\"post-text\" itemprop=\"text\"><a href=\"something.com\">sometext for example</a></div>";
Document doc = Jsoup.parse(html);
Elements elts = doc.select("*:containsOwn(sometext)");
for(Element e : elts) {
System.out.println(e.outerHtml());
}
<a href="something.com">sometext for example</a>
:matchesOwn(regex)
- If you want to find element with more elaborate text.
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.