有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何用jsoup解析span title?

我正在尝试使用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) 个答案

  1. # 1 楼答案

    好了:

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