如何用jsoup解析span标题?

时间:2011-10-07 15:29:17

标签: java android dom jsoup

我正在尝试使用JSOUP解析此内容的标题..

<div class="article">
<div class="articleHead review">

    <h1 class="item"><span class="fn">OnLive</span> review</h1>
    <h2 class="subGrey"><span class=""></span>Cloud gaming has arrived in the UK, but can our infrastructure make the most of it?</h2>

我想解析span类OnLive Review。 和子标题

到目前为止,我已尝试过这个...

 try{
                     Elements titleElements = jsDoc.getElementsByTag("div");
                         for(Element TitleElement : titleElements){
                             if(TitleElement.attr("class").equals("articleHeader review")){
                                 Element articleHeader = jsDoc.select("#item").first();
                                    String header = articleHeader.text();


                                        System.out.println(TitleElement.text());

                                       title = header.toString();
                                        Log.e("TITLE", title);

                                     }

                    }


                    }
                    catch(Exception e){
                        System.out.println("Couldnt get content");
                    }

没有运气。

1 个答案:

答案 0 :(得分:1)

你去了:

Element header = jsDoc.select("h1.item span.fn");
Element sub = jsDoc.select("h2.subGrey span");