Posted on 2008-03-09 10:46
G_G 阅读(1504)
评论(2) 编辑 收藏 所属分类:
javaGeneral
数据扒出效果
双色球(2008001)=02,04,07,09,14,29#03
双色球(2008002)=03,04,18,22,25,29#09
..
junit代码
package test;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import junit.framework.TestCase;
public class HttpConn extends TestCase {
public void testT() throws Exception {
zq :
for(int i=2008001;true;i++){
String num = getQihao(i) ;
System.out.println("双色球("+i+")="+ num);
if(num==null||num.equals("")) break zq;
}
}
public String getQihao(int qihao) throws Exception {
URL url = new URL("http://www.cnlot.net/ssq/details.php?issue="+qihao);
URLConnection uconn = url.openConnection();
String num = "";
InputStream in = uconn.getInputStream();
byte[] bs = new byte[in.available()];
in.read(bs);
String date = new String(bs) ;
Pattern pa = Pattern.compile(" .+color=red>([0-9][0-9])<.+" );
Matcher m = pa.matcher(date);
while( m.find() )
num+= m.group(1)+",";
pa = Pattern.compile(" .+color=blue>([0-9][0-9])<.+" );
m = pa.matcher(date);
while( m.find() )
num = num.substring( 0,num.length()-1 )+"#"+m.group(1) ;
pa = Pattern.compile("^(([0-9][0-9],){5,}[0-9][0-9]#([0-9][0-9],)*[0-9][0-9]\\|)*(([0-9][0-9],){5,}[0-9][0-9]#([0-9][0-9],)*[0-9][0-9])*$");
m = pa.matcher(num);
if( m.find() )
return num ;
else
return null ;
}
}