2016-07-01 5 views
-2
<p class="name"> 
<a href="/shop/view.php?index_no=22176&amp;cate="><strong class="title displaynone"> :</strong>T-shritsT</a> <span class="icon"></span></p> 
<ul class="xans-element- xans-product xans-product-listitem"> 
<li class=" xans-record-"><strong class="title displaynone"><span style="font-size:12px;color:#555555;">price</span> :</strong> <span style="font-size:12px;color:#555555;"><s></s>$20</span></li> 

In diesem Code mag ich Text erhalten nur "T-shrits" und den Preis ohne "$ 20" ':' und "Preis"Wie diesen Tag zu analysieren, mit jsoup mit

Dies ist mein Code ,

Elements goods = document.select("p.name > a"); 
     for (Element e :goods) { 
     System.out.println("------------------------------------------"); 
     System.out.println("goods" + e.text()); } 
+1

Haben Sie selbst etwas probiert? –

Antwort

0

Versuchen Sie folgendes:

public class Test { 
    public static void main(String[] args) { 
     String s="<p class=\"name\">\n" + 
       "<a href=\"/shop/view.php?index_no=22176&amp;cate=\"><strong class=\"title displaynone\"> :</strong>T-shritsT</a> <span class=\"icon\"></span></p>\n" + 
       "<ul class=\"xans-element- xans-product xans-product-listitem\">\n" + 
       "<li class=\" xans-record-\"><strong class=\"title displaynone\"><span style=\"font-size:12px;color:#555555;\">price</span> :</strong> <span style=\"font-size:12px;color:#555555;\"><s></s>$20</span></li>"; 
     Document document= Jsoup.parse(s); 
     document.select("strong").remove(); 
     Whitelist whitelist = Whitelist.basic(); 
     System.out.println(Jsoup.parse(Jsoup.clean(document.toString(), whitelist)).text()); 

    } 


} 

Ausgabe: T-shritsT $20