- /**
- * 得到网页中图片的地址
- */
- public static List<String> getImgStr(String htmlStr){
- String img="";
- Pattern p_image;
- Matcher m_image;
- List<String> pics = new ArrayList<String>();
- String regEx_img = "<img.*src=(.*?)[^>]*?>"; //图片链接地址
- p_image = Pattern.compile
- (regEx_img,Pattern.CASE_INSENSITIVE);
- m_image = p_image.matcher(htmlStr);
- while(m_image.find()){
- img = img + "," + m_image.group(); //个人觉得这句没用
- Matcher m = Pattern.compile("src=\"?(.*?)
- (\"|>|\\s+)").matcher(img); //匹配src
- while(m.find()){
- pics.add(m.group(1));
- }
- }
- return pics;
- }
- //重点在于正则表达式 <img.*src=(.*?)[^>]*?>
- // src=\"?(.*?)(\"|>|\\s+)
通过正则表达式来截取图片路径
最新推荐文章于 2022-12-05 19:32:38 发布