Jsoup Html解析器获取内容

时间:2017-08-23 01:24:33

标签: jsoup

我需要从html下面提取349,900美元。 我该怎么做?

<div id="header" class="banner">
    <header id="h" class="menu">
        <a href="#" class="logo"><img src="../img/a.jpg"></a>
        <nav>
            <ul>            
                <li><a href="#">Início</a></li>
                <li><a href="#">Categorias</a></li>
                <li><a href="#">Blog</a></li>
                <li><a href="#">Membros</a></li>
            </ul> 
        </nav>            
    </header>
</div>
<script> 
window.onload =function(){
        var header =document.getElementById('h');
        alert(header.clientHeight); 
}

1 个答案:

答案 0 :(得分:0)

您可以使用var assocs = _context.Assoc.ToList() .Where(x => x.Model == model) .Where(predicate); 方法使用p.price b CSS选择器提取此价格,例如

String html = "<p class=\"price asking help \">\n" +
            "                <span class=\"title\">Asking Price:</span><b>$349,900<span class=\"help\" title=\"The total asking price of the business for sale.\"><i class=\"fa fa-question-circle\"></i></span></b>\n" +
            "            </p>";

Document doc = Jsoup.parse(html);

String price = doc.select("p.price b").first().text();

System.out.println(price);

输出

$349,900

您可以在此处查看其工作原理: Element.select(String cssQuery)