使用jsoup从网页内容获取内容时出现问题



我在使用jsoup获取某些内容时遇到问题。实际上内容的形式是这样的:

<li>
<p>
    <span class=”title” style =”font-weight:lighter”> Title </span> <br/>
    <span class=”time”>Time Date </span>
</p>
<p class=””> Description
</p>
</li>

我通过使用此代码片段获得标题日期时间

Document doc = Jsoup.connect(url).timeout(60*1000).followRedirects(true).get();
        for( Element element : doc.select("#incidents") ) {
            String title = element.select("span.title").text() ;
            String timeDate = element.select("span.time").text() ; 
            //String description =  element.select("p").first().text();
        }

现在我想得到描述,即<p class=””> Description</p>,但我对此一无所知。我尝试了许多链接的不同方法,但都无济于事。任何对此有想法的人。

我得到了解决方案;我现在使用

String description = element.select("p[class= ]").text();

它为我提供了所需的数据/内容。

最新更新