抓取页面源代码这个不用我写吧,我只负责价格这块分析package com.fkjava.learning;
import java.util.regex.*;
public class RegexSearch {
public static void main(String [] args){
String info ="
"
+ "
"
"
+ ""
+ "178"
+ "
+"
"
+ "
"
"
+ ""
+ "33.99"
+ "
+"
"
+ "
"
";
+ ""
+ ""
+ "
//Pattern -它就是代表正则表达式模板
//Pattern pattern = Pattern.compile("[\\d\\.]+");
Pattern pattern = Pattern.compile("[\\w\\.]*?");
//Matcher -代表一个匹配工具类
Matcher matcher =pattern.matcher(info);
int i=1;
//如果可以找到匹配“正则表达式”的子串
while(matcher.find()){
// 打印出上次找到的子串
//System.out.println(matcher.group());
String matchstr= matcher.group();
matchstr=matchstr.substring(matchstr.indexOf(">") +1 , matchstr.indexOf(""));
System.out.println( "第" + i + "个价格是:" + matchstr);
i ++;
}
}
}