如何使用 Jsoup 从链接中提取 href?

发布于 2024-11-27 19:15:46 字数 1513 浏览 0 评论 0原文

我想

index.php?limitstart=0&picno=0&gallery_key=92
index.php?limitstart=0&picno=1&gallery_key=92
index.php?limitstart=0&picno=2&gallery_key=92

使用 Jsoup 从这个 html 获取此链接:

<tr> 
<td style="padding: 8px;"><a onclick="redx_gallery_showImage(0);return false;" href="/module/gallery/index.php?limitstart=0&amp;picno=0&amp;gallery_key=92"><img width="90" height="90"  style='border: 1px #BAB9AF solid'   src='/redx_tools/mb_image.php/cid.077117104075119048121090118052048061/gid.10/pyrit_club_2_buche.jpg' border='1'    alt=''/></a></td> 
    <td style="padding: 8px;"><a onclick="redx_gallery_showImage(1);return false;" href="/module/gallery/index.php?limitstart=0&amp;picno=1&amp;gallery_key=92"><img width="90" height="90"  style='border: 1px #BAB9AF solid'   src='/redx_tools/mb_image.php/cid.085057100083102116053082117052115061/gid.10/pyrit_club_2_weiss.jpg' border='1'    alt=''/></a></td> 
    <td style="padding: 8px;"><a onclick="redx_gallery_showImage(2);return false;" href="/module/gallery/index.php?limitstart=0&amp;picno=2&amp;gallery_key=92"><img width="90" height="90"  style='border: 1px #BAB9AF solid'   src='/redx_tools/mb_image.php/cid.120068065087108097121088078055048061/gid.10/pyrit_club_2_wei_2.jpg' border='1'    alt=''/></a></td> 
</tr> 

有什么想法吗?谢谢

I want to get this links :

index.php?limitstart=0&picno=0&gallery_key=92
index.php?limitstart=0&picno=1&gallery_key=92
index.php?limitstart=0&picno=2&gallery_key=92

from this html using Jsoup :

<tr> 
<td style="padding: 8px;"><a onclick="redx_gallery_showImage(0);return false;" href="/module/gallery/index.php?limitstart=0&picno=0&gallery_key=92"><img width="90" height="90"  style='border: 1px #BAB9AF solid'   src='/redx_tools/mb_image.php/cid.077117104075119048121090118052048061/gid.10/pyrit_club_2_buche.jpg' border='1'    alt=''/></a></td> 
    <td style="padding: 8px;"><a onclick="redx_gallery_showImage(1);return false;" href="/module/gallery/index.php?limitstart=0&picno=1&gallery_key=92"><img width="90" height="90"  style='border: 1px #BAB9AF solid'   src='/redx_tools/mb_image.php/cid.085057100083102116053082117052115061/gid.10/pyrit_club_2_weiss.jpg' border='1'    alt=''/></a></td> 
    <td style="padding: 8px;"><a onclick="redx_gallery_showImage(2);return false;" href="/module/gallery/index.php?limitstart=0&picno=2&gallery_key=92"><img width="90" height="90"  style='border: 1px #BAB9AF solid'   src='/redx_tools/mb_image.php/cid.120068065087108097121088078055048061/gid.10/pyrit_club_2_wei_2.jpg' border='1'    alt=''/></a></td> 
</tr> 

Any ideas? Thank You

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

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

发布评论

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

评论(1

半步萧音过轻尘 2024-12-04 19:15:46

您需要知道公共容器元素的 id ,以便可以在单个 CSS 选择中获取它们。根据来源,它是

所以,这应该做:

Elements links = document.select("#redx_gallery_thumb_list a");

for (Element link : links) {
    String href = link.attr("href");

    // Or if you want to have absolute URL instead, so that you can leech them.
    String absUrl = link.absUrl("href");

    // ...
}

You need to know the id of a common container element so that you can get them all in a single CSS select. According to the source it's the <div id="redx_gallery_thumb_list">.

So, this should do:

Elements links = document.select("#redx_gallery_thumb_list a");

for (Element link : links) {
    String href = link.attr("href");

    // Or if you want to have absolute URL instead, so that you can leech them.
    String absUrl = link.absUrl("href");

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