使用 jsoup 解析表时出现问题

发布于 2025-01-04 21:03:40 字数 464 浏览 3 评论 0原文

我已经坚持这个问题好几天了。我正在尝试创建一个用于论坛 Fightlockdown(它是一个 MMA 论坛)的应用程序。

我遇到麻烦的区域是 http://fightlockdown.com/ 等页面forum/forumdisplay.php?f=1 我想将表格中的每个部分显示为一行,但无法仅抓取这些部分,即 UFC、终极战士等...

我最接近的能够得到就是抢夺所有的锚标记,但页面上显然还有其他标记,如果我不正确地将它们从返回的元素中删除,它们可能会导致我的结果丢失。

我无法弄清楚如何让表格缩小我的结果范围,因为据我所知 doc.select("table.tborder") 不会产生任何结果,doc.select("td. alt1 活动”)。

任何帮助将非常感激。提前致谢。

I have been stuck on this for a few days now. I am attempting to create an app that is for the forum fightlockdown (its an MMA forum).

The area where I am running into trouble is on pages such as http://fightlockdown.com/forum/forumdisplay.php?f=1 where I would like to display each section in a table as a row but am having trouble grabbing only the sections i.e. UFC, The Ultimate Fighter, etc...

The closest I have been able to get is grabbing all of the anchor tags but there are obviously others on the page which could throw off my results if I don't remove them from the returned Elements correctly.

I have not been able to figure out how to get the table to narrow down my results since as far as I can tell doc.select("table.tborder") does not yield any results and neither does doc.select("td.alt1Active").

Any help would be very much appreciated. Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坦然微笑 2025-01-11 21:03:40

您对要寻找的内容不是很具体,所以我会抛出一些代码,看看它是否是您要寻找的内容。

具体来说,在此页面上,您尝试拉取的 div 具有与其关联的两个类之一。此代码选择这些 div 并迭代它们,然后打印出 div 中的锚标记。

    Document doc = Jsoup.connect("http://fightlockdown.com/forum/forumdisplay.php?f=1").get();
    for (Element div : doc.select("div.forumold_lock, div.old_lockwindowbg")) {
        System.out.println(div.select("a"));
    }

如果您需要更多帮助,请告诉我。

You are not very specific in what you are looking for, so I'll throw some code out there and see if it's what you are looking for.

On this page specifically, the divs you are trying to pull have one of two classes associated with them. This code selects those divs and iterates over them and then prints out the anchor tags in the divs.

    Document doc = Jsoup.connect("http://fightlockdown.com/forum/forumdisplay.php?f=1").get();
    for (Element div : doc.select("div.forumold_lock, div.old_lockwindowbg")) {
        System.out.println(div.select("a"));
    }

Let me know if you need any more help.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文