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; }
-----------------------有任何问题可以在评论区评论,也可以私信我,我看到的话会进行回复,欢迎大家指教------------------------
(蓝奏云官网有些地址失效了,需要把请求地址lanzous改成lanzoux才可以)