JAVA匹配html中所有img标签

public static List<String> getImg(String htmlStr) {
        List<String> list = new ArrayList<String>();
        String img = "";
        Pattern p_image;
        Matcher m_image;
        // String regEx_img = "<img.*src=(.*?)[^>]*?>"; //图片链接地址
        String regEx_img = "<img.*src\\\\s*=\\\\s*(.*?)[^>]*?>";
        p_image = Pattern.compile("^data:image/(png|gif|jpg|jpeg|bmp|tif|psd|ICO);base64,.*");
        //p_image = Pattern.compile(regEx_img, Pattern.CASE_INSENSITIVE);
        m_image = p_image.matcher(htmlStr);
        while (m_image.find()) {
            // 得到<img />数据
            img = m_image.group();
            System.out.println(img.toString());
        }
        return list;
    }

  

posted @ 2019-05-03 15:12  yvioo  阅读(2231)  评论(0编辑  收藏  举报