![](/img/trans.png)
[英]How to fetch an element from arraylist and set it as the class(HTML tag) name?
[英]Get text from html tag using single class name, the html tag will contain multiple class
我有一個html行,其中標簽內有標簽,一個標簽包含多個類。 我需要用單個類名提取文本(我只知道一個類名)
<p class="Body1"><span class="style3"></span><span class="style1">W</span><span class="Allsmall style5">extract this text </span><span class="style5">unwanted text </span></p>
我知道一個類名Allsmall,我想在Java中使用Jsoup從html行中提取文本“ extract this text”。
您可以使用選擇器語法根據其CSS類屬性檢索特定元素:
Document doc = Jsoup.parse(
new File("input.html"),
"UTF-8",
"http://sample.com/");
Element allSmallSpan = doc.select("span.Allsmall").first(); // Retrive the first <span> element which belongs to "Allsmall" class
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.