【问题标题】:Jsoup prasring heading h2Jsoup prasring 标题 h2
【发布时间】:2014-03-26 00:21:28
【问题描述】:

大家好,我正在尝试解析来自本网站 http://feed43.com/alytus_06.xml 的标题文本。

html代码:

<html>
<head></head>
<body onload="doLoad()">
    <div class="body feed-preview">
        <table class="main" style="margin-top:10px">...</table>
        <div class ="main">
            <h1>ALYTUS_06</h1>
            <p>ALYTUS_06</p>
            <p>...</p>
            <p class="date-preview" style="margin-bottom:0px;">Last Updated: Mon, 24 Feb 2014 10:01:54 GMT</p>
        </div>
        <div class ="main">
            <h2>
                <span class="bullet">&nbsp;</span>
                "-1"
            </h2>
        <div class="p" id="item_1">...</div>
        <h2>..</h2>
        <div class="p" id="item_2">...</div>
        </div>
        <div class="main footer">       
              Feed43 v. 1.3. Copyright © 2006–2011 A.I.Studio. All rights reserved.
        </div>
    </div>
</body>

    public static void main( String[] args ) throws IOException
{
    Document doc = Jsoup.parse("UTF-8", "http://feed43.com/alytus_06.xml");
        for (Element e : doc.select("h2")) {
            System.out.println(e.text());
        }
}

我无法从这段代码中的 h2 中的 div.class main 中提取温度“-1”,也许有人可以帮助我?

【问题讨论】:

  • 你的程序打印出什么?

标签: java html parsing dom jsoup


【解决方案1】:

要获取第一个元素,请像这样更改您的代码

Document doc = Jsoup.connect("http://feed43.com/alytus_06.xml").get();
Element ele=doc.select("item title").first();
System.out.println(ele.text());

获取item中所有带有title标签的元素

Document doc = Jsoup.connect("http://feed43.com/alytus_06.xml").get();
Elements ele=doc.select("item title");
for(Element element:ele)
{
   System.out.println(element.text());
}

【讨论】:

  • 是否可以获得所有元素而不是第一个元素?谢谢。
  • 你能指定你需要的数据吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-02-19
  • 1970-01-01
  • 1970-01-01
  • 2010-11-12
  • 2016-09-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多