如何从 Jsoup 选择器方法获取 Elements 对象
我对 JSoup 很困惑。我知道我曾经让它工作过,但现在我
根本无法让它工作。 中包含此代码
我实际上已经创建了一个空的 Java 类文件,并在其主类 。看起来应该是这样,但事实并非如此?老实说,它看起来对我来说仍然是正确的,但是我似乎无法在我的一生中获得有效的 Elements 对象。 :/
String data = HTML_DOCUMENT_CODE;
Elements allTexts = Jsoup.parse(data).select(".gc-message-sms-text");
System.out.println("string is: " + allTexts.toString());
System.out.println("size is: " + allTexts.size());
输出:
Size is:
size is: 0
I am so confused with JSoup. I know that I had it working at one point, but now I can't get
it working at all. I've literally created an empty Java Class file with this code in its
main class. It looks like it should would but however that is not the case? It still honestly looks like it's written correctly to me, however I cannot seem to get a valid Elements object for the life of me. :/
String data = HTML_DOCUMENT_CODE;
Elements allTexts = Jsoup.parse(data).select(".gc-message-sms-text");
System.out.println("string is: " + allTexts.toString());
System.out.println("size is: " + allTexts.size());
Output:
Size is:
size is: 0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有解析完整的文档,而是解析一个片段,因此也许这会更好:
http:// /jsoup.org/cookbook/input/parse-body-fragment
You aren't parsing a complete document but a fragment so maybe this would work better:
http://jsoup.org/cookbook/input/parse-body-fragment