码迷,mamicode.com
首页 > 其他好文 > 详细

解析小例子

时间:2014-09-04 16:37:29      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   ar   for   div   代码   sp   log   

/**
  * 
  * @param s
  * @return 获网页标题
  */
 public String getTitle(final String s)
 {
  String regex;
  String title = "";
  final List<String> list = new ArrayList<String>();
  regex = "<title>.*?</title>";
  final Pattern pa = Pattern.compile(regex, Pattern.CANON_EQ);
  final Matcher ma = pa.matcher(s);
  while (ma.find())
  {
   list.add(ma.group());
  }
  for (int i = 0; i < list.size(); i++)
  {
   title = title + list.get(i);
  }
  return outTag(title);
 }
/**
  * 
  * @param s
  * @return 获链接
  */
 public List<String> getLink(final String s)
 {
  String regex;
  final List<String> list = new ArrayList<String>();
  regex = "<a[^>]*href=(\"([^\"]*)\"|\‘([^\‘]*)\‘|([^\\s>]*))[^>]*>(.*?)</a>";
  final Pattern pa = Pattern.compile(regex, Pattern.DOTALL);
  final Matcher ma = pa.matcher(s);
  while (ma.find())
  {
   list.add(ma.group());
  }
  return list;
 }
/**
  * 
  * @param s
  * @return 获脚本代码
  */
 public List<String> getScript(final String s)
 {
  String regex;
  final List<String> list = new ArrayList<String>();
  regex = "<script.*?</script>";
  final Pattern pa = Pattern.compile(regex, Pattern.DOTALL);
  final Matcher ma = pa.matcher(s);
  while (ma.find())
  {
   list.add(ma.group());
  }
  return list;
 }
/**
  * 
  * @param s
  * @return 获CSS
  */
 public List<String> getCSS(final String s)
 {
  String regex;
  final List<String> list = new ArrayList<String>();
  regex = "<style.*?</style>";
  final Pattern pa = Pattern.compile(regex, Pattern.DOTALL);
  final Matcher ma = pa.matcher(s);
  while (ma.find())
  {
   list.add(ma.group());
  }
  return list;
 }

 

解析小例子

标签:style   blog   color   ar   for   div   代码   sp   log   

原文地址:http://www.cnblogs.com/gisblogs/p/3956165.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!