大家好,我正在尝试解析此网站的标题文本 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"> </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”,也许有人可以帮助我?
最佳答案
要获取第一个元素,请像这样更改代码
Document doc = Jsoup.connect("http://feed43.com/alytus_06.xml").get();
Element ele=doc.select("item title").first();
System.out.println(ele.text());
获取项目中带有标题标签的所有元素
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());
}
关于java - Jsoup prasring 标题 h2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21986055/