Jsoup解析的例子 之 選取器

來源:互聯網
上載者:User

標籤:

/***

Jsoup的選取器真的是很強大,多多嘗試會感覺很有意思

*/

public class TestJsoup {
    
    public static void main(String[] args) {
        String str = "<a href=\"/2951/\">一汽-福士奧迪-<h1>奧迪Q3</h1></a>";
        parse("a",str);
        
        String  str1="<div class=\"breadnav fn-left\">當前位置:<a target=\"_self\" href=\"/\">首頁</a>&nbsp;&gt;&nbsp;<a target=\"_self\" href=\"/suva/\">緊湊型SUV</a>&nbsp;&gt;&nbsp;<a target=\"_self\" href=\"/2951/\">奧迪Q3</a>&nbsp;&gt;&nbsp;綜述</div>";
        parse("div.breadnav.fn-left a:nth-child(3)",str1);
        
        String str2 = "<div class=\"autoseries-info\"><dl><dt>新車指導價:<a>24.98-42.88萬</a> <a>(15款車型)</a></dt><dt>二手車價格:<a></a></dt></dl></div>";
        parse("div.autoseries-info dt:contains(新車指導價) a:nth-child(1)",str2);
        
    }

    private static void parse(String selector,String str) {
        Document doc = Jsoup.parse(str);
        Elements elements = doc.select(selector);;
        String text = elements.text();
        System.out.println(text.replaceAll(" ", ""));
        
    }
    
}


-------------------------------------------------------

jsoup中文協助文檔

http://www.open-open.com/jsoup/selector-syntax.htm


Jsoup解析的例子 之 選取器

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.