[英]How to extract bold content using jsoup from various html pages of different types of bold html expression?
我想知道如何從各種不同的html頁面中提取粗體內容,而不必所有html頁面都使用它,所以說“ b”標簽或“ font-weight:bold”。 我想知道是否有任何通用的方式來查找粗體內容或是否有詳盡的html表達式列表。 同樣,在內容大小方面,我希望查找相同的內容。
我的代碼草稿如下,以防萬一
public class Main {
public static void main(String[] args) throws IOException {
File input = new File("");
//String headingcriteria="font[style*=font-weight:bold]";
String headingcriteria = "b";
Document doc = Jsoup.parse(input, "UTF-8");
doc.select("table").remove();
Elements boldlist = doc.select("*");
int elementno=1;
for (Element bold: boldlist){
try{
System.out.println("No: "+elementno+" ::: Content tagname: "+bold.tagName()+" ::: Content Size: "+
getElementContentSize(bold.attr("style")));
}catch(ArrayIndexOutOfBoundsException e){
System.out.println("No: "+elementno+" ::: Content tagname: "+bold.tagName()+" ::: Content Size: NANA");
}
elementno+=1;
}
}
public static String getElementContentSize(String attribs){
String temp=attribs.split("font-size:")[1];
return temp.substring(0,temp.indexOf("pt"));
}}
要搜索樣式標簽:
Elements divTags = doc.getElementsByTag("div");
for (Element div : divTags) {
if (div.attr("style").equals("font-family:'Segoe UI',Arial,sans-serif")) {
System.out.println(div.text());
}
}
要搜索b粗體標簽:
Elements boldTags = doc.getElementsByTag("b");
for (Element tag : boldTags) {
System.out.println(tag.text());
}
要搜索強壯的粗體標簽:
Elements strongTags = doc.getElementsByTag("strong");
for (Element tag : strongTags) {
System.out.println(tag.text());
}
希望這就是您想要的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.