gpt4 book ai didi

android - 从标签android中提取图片src

转载 作者:行者123 更新时间:2023-11-30 01:15:53 25 4
gpt4 key购买 nike

我在 html 中有一些 img 标签。我使用 Regex 获取 img 标签。我写了一些代码,我的代码只在一个 img 标签上工作。

String imgRegex = "<[iI][mM][gG][^>]+[sS][rR][cC]\\s*=\\s*['\"]([^'\"]+)['\"][^>]*>";

Pattern p = Pattern.compile(imgRegex);
Matcher m = p.matcher(htmlString);

if (m.find()) {
String imgSrc = m.group(1);

String base = Environment.getExternalStorageDirectory().getAbsolutePath().toString()+"/tanadgomaaa";
String imagePath = "file://"+ base + "/test.jpg";
imgSrc=imgSrc.replace(imgSrc,imagePath);



}

谁能告诉我如何从 html 字符串中获取所有 img 标签?谢谢

最佳答案

    String imgRegex = "(?i)<img[^>]+?src\\s*=\\s*['\"]([^'\"]+)['\"][^>]*>";

Pattern p = Pattern.compile(imgRegex);
Matcher m = p.matcher(htmlString);

while(m.find()) {
String imgSrc = m.group(1);

String base = Environment.getExternalStorageDirectory().getAbsolutePath().toString()+"/tanadgomaaa";
String imagePath = "file://"+ base + "/test.jpg";
imgSrc=imgSrc.replace(imgSrc,imagePath);



}

关于android - 从<img>标签android中提取图片src,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37868325/

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