gpt4 book ai didi

java - 在 jsoup 中搜索包含特定文本的图像类

转载 作者:行者123 更新时间:2023-11-29 20:57:33 26 4
gpt4 key购买 nike

如果我在 div 中有以下图像,我将如何执行 jsoup 查询,该查询仅返回具有包含文本“absmiddle”的类的图像?

<div>
<img class="absmiddle-blah foo-bar" src="google.com/image.png" \>
<img class="absmiddle-blah2 foo-bar2" src="google.com/image.png" \>
<img class="ablehe-bla2h foo-bar3" src="google.com/image.png" \>
<img class="absmiddle-bl2ah foo-bar4" src="google.com/image.png" \>
<img class="blah-bl2ah foo-bar4" src="google.com/image.png" \>
<img class="absmiddle-bl2ah foo-bar4" src="google.com/image.png" \>
<img class="sdfdle-bl2ah foo-bar4" src="google.com/image.png" \>
</div>

最佳答案

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

public class Main {

public static void main(String[] args) throws Exception {
String html = "<div>"+
"<img class=\"absmiddle-blah foo-bar\" src=\"google.com/image.png\" \\>"+
"<img class=\"absmiddle-blah2 foo-bar2\" src=\"google.com/image.png\" \\>"+
"<img class=\"ablehe-bla2h foo-bar3\" src=\"google.com/image.png\" \\>"+
"<img class=\"absmiddle-bl2ah foo-bar4\" src=\"google.com/image.png\" \\>"+
"<img class=\"blah-bl2ah foo-bar4\" src=\"google.com/image.png\" \\>"+
"<img class=\"absmiddle-bl2ah foo-bar4\" src=\"google.com/image.png\" \\>"+
"<img class=\"sdfdle-bl2ah foo-bar4\" src=\"google.com/image.png\" \\>"+
"</div>";

Document doc = Jsoup.parse(html);
Elements els = doc.select("img[class*=absmiddle]");
System.out.println(els);
}
}

可以查看here有关 Jsoup 功能的更多示例

关于java - 在 jsoup 中搜索包含特定文本的图像类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27199252/

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