第一步導包:html
implementation 'org.jsoup:jsoup:1.10.3'
第二步:需獲取解析的Html:node
<p> <myfont style="color:#ff0000;">
<myfont style="font-size:12px;">
<myfont style="font-family:tahoma,geneva,sans-serif;">一、如您須要進行轉帳,請您登陸e錢莊,選擇【首頁】-【一鍵付】或者選擇【個人】—【個人帳戶】—【轉帳】</myfont>
</myfont>
</myfont>
</p>
<p> <myfont style="font-size:16px;">
<myfont style="color:#ff0000;">
<myfont style="font-family:tahoma,geneva,sans-serif;">二、選擇轉出帳戶,並填寫收款信息,根據提示進行操做。使用e錢莊轉帳不要任何手續費哦!</myfont>
</myfont>
</myfont>
</p>
<p>
</p>
第三步,解析的Java代碼:spa
public static void main(String[] args) { String string = "<p>\n" + " \t<myfont style=\"color:#ff0000;\"><myfont style=\"font-size:12px;\"><myfont style=\"font-family:tahoma,geneva,sans-serif;\">一、如您須要進行轉帳,請您登陸e錢莊,選擇【首頁】-【一鍵付】或者選擇【個人】—【個人帳戶】—【轉帳】</myfont></myfont></myfont></p>\n" + " <p>\n" + " \t<myfont style=\"font-size:16px;\"><myfont style=\"color:#ff0000;\"><myfont style=\"font-family:tahoma,geneva,sans-serif;\">二、選擇轉出帳戶,並填寫收款信息,根據提示進行操做。使用e錢莊轉帳不要任何手續費哦!</myfont></myfont></myfont></p>\n" + " <p>\n" + " \t </p>"; getElementsMethod(string); } /** * * @param html 這裏傳入Html字符串 */ private static String getElementsMethod(String html) { org.jsoup.nodes.Document doc = Jsoup.parse(html); Elements rows = doc.select("myfont"); Elements sty = rows.get(1).select("style"); String styleStr = rows.get(1).attr("style"); System.out.println(rows.html() + "---" + " sty:" + sty.text() + " --- " + styleStr); String fontSize = styleStr.substring(styleStr.indexOf(":") + 1, styleStr.length()); System.out.println("如下是打印font-size:配置的值...."); System.out.println(fontSize); return fontSize; }
第四步,解析的結果:code
<myfont style="font-size:12px;"> <myfont style="font-family:tahoma,geneva,sans-serif;"> 一、如您須要進行轉帳,請您登陸e錢莊,選擇【首頁】-【一鍵付】或者選擇【個人】—【個人帳戶】—【轉帳】 </myfont> </myfont> <myfont style="font-family:tahoma,geneva,sans-serif;"> 一、如您須要進行轉帳,請您登陸e錢莊,選擇【首頁】-【一鍵付】或者選擇【個人】—【個人帳戶】—【轉帳】 </myfont> 一、如您須要進行轉帳,請您登陸e錢莊,選擇【首頁】-【一鍵付】或者選擇【個人】—【個人帳戶】—【轉帳】 <myfont style="color:#ff0000;"> <myfont style="font-family:tahoma,geneva,sans-serif;"> 2、選擇轉出帳戶,並填寫收款信息,根據提示進行操做。使用e錢莊轉帳不要任何手續費哦! </myfont> </myfont> <myfont style="font-family:tahoma,geneva,sans-serif;"> 2、選擇轉出帳戶,並填寫收款信息,根據提示進行操做。使用e錢莊轉帳不要任何手續費哦! </myfont> 二、選擇轉出帳戶,並填寫收款信息,根據提示進行操做。使用e錢莊轉帳不要任何手續費哦!--- sty: --- font-size:12px; 如下是打印font-size:配置的值.... 12px;
如下是打印font-size:配置的值....
12px;