gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:25:10 26 4
gpt4 key购买 nike

我想得到这个链接:

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

从这个 html 使用 Jsoup :

<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>

有什么想法吗?谢谢你

最佳答案

你需要知道 id一个共同的容器元素,这样你就可以在一个 CSS 选择中得到它们。根据source这是 <div id="redx_gallery_thumb_list"> .

所以,应该这样做:

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");

// ...
}

关于java - 如何使用 Jsoup 从链接中提取 href?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6933635/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com