public class test { /** * @title: main * @description: * @param args * @author * @date 2016年2月17日 * 1、去掉字符串中所有的标签,获取纯文本内容 * 2、获取html节点中img的src路径 */ public static void main(string[] args) { string html = "<div><p style='color:red;'>12132第一串字符</p></div><br /><div><p>这是第二窜字符</p></div><img style="max-width:90%" src='_image/12/label'/ alt="html字符操作_html/css_WEB-ITnose" ><img style="max-width:90%" src='_image/13/label'/ alt="html字符操作_html/css_WEB-ITnose" ><img style="max-width:90%" src='_image/14/label'/ alt="html字符操作_html/css_WEB-ITnose" >"; Pattern p = Pattern.compile("<img [^ alt="html字符操作_html/css_WEB-ITnose" >]+src\s*=\s*['"]([^'"]+)['"][^>]*>"); Matcher m = p.matcher(html); List<String> srcs = new ArrayList<String>(); while(m.find()){ srcs.add(m.group(1)); } String regex = "<[^>]*>"; String str = html.replaceAll(regex, ""); System.out.println(str+"
"+srcs.get(0)); }}
HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号