0
我在JSoup库中遇到了一些麻烦,特别是在尝试选择标签内的文本时。输出应该是'HELLO WORLD'Android - JSoup Select
我会想到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>
任何想法?
谢谢!
感谢maclir! – user2568848
不客气:) – maclir