我在使用 JSoup 库时遇到了一些问题,特别是在尝试选择标签内的文本时。输出应为“HELLO WORLD”
我会认为 doc.select("div.sub").get(0); 会做的伎俩,但它不会返回任何东西。有没有我无知错过的方法?
我的代码:
final String url = "http://www.my123url.com,";
Element myText;
Document doc;
try {
doc = Jsoup.parse(new URL(url).openStream(), "UTF-8",
url);
myText = doc.select("div.sub").get(0);
System.out.println("Text is: " + myText.text();
return myText.text();
} catch (Exception e) {
System.out.println("The exception caught is: " + e);
}
我试图抓取的代码:
<div id="content">
<div class="main-row" style="margin-bottom: 15px;">
<div class="sub" style="font-size: 18px; line-height: 27px;">
<cufon alt="HELLO" class="cufon cufon-canvas" style="width: 45px; height: 18px;">
<canvas height="28" style="width: 75px; height: 24px; top: -2px; left: -10px;" width="77"></canvas>
<cufontext>HELLO
</cufontext>
</cufon>
<cufon alt="WORLD " class="cufon cufon-canvas" style="width: 20px; height: 18px;">
<canvas height="28" style="width: 63px; height: 20px; top: -5px; left: -10px;" width="63"></canvas>
<cufontext>WORLD
</cufontext>
</cufon>
</div>
</div>
</div>
有任何想法吗?
谢谢!