如下所示:

/**
  * 得到网页中图片的地址
  * @param sets html字符串
  */
 public Set<String> getImgStr(String htmlStr) {
  Set<String> pics = new HashSet<String>();
  String img = "";
  Pattern p_image;
  Matcher m_image;
  String regEx_img = "<img.*src\\s*=\\s*(.*?)[^>]*?>";
  p_image = Pattern.compile(regEx_img, Pattern.CASE_INSENSITIVE);
  m_image = p_image.matcher(htmlStr);
  while (m_image.find()) {
   // 得到<img />数据
   img = m_image.group();
   // 匹配<img>中的src数据
   Matcher m = Pattern.compile("src\\s*=\\s*\"?(.*?)(\"|>|\\s+)").matcher(img);
   while (m.find()) {
    pics.add(m.group(1));
   }
  }
  return pics;
 }

相关文章:

  • 2021-07-06
  • 2022-12-23
  • 2022-12-23
  • 2022-01-02
  • 2022-12-23
  • 2022-12-23
  • 2021-11-09
  • 2022-02-08
猜你喜欢
  • 2021-07-15
  • 2022-12-23
  • 2022-01-10
  • 2022-12-23
  • 2022-12-23
  • 2021-07-13
  • 2021-11-14
相关资源
相似解决方案