抓取新浪彩票数据

package com.overseas;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class DownLoadDB {
 
 public static void main(String[] args) throws Exception{
  String sCurrentLine;
  String sTotalString;
  sCurrentLine="";
  sTotalString="";
  java.io.InputStream l_urlStream;
  java.net.URL l_url = new java.net.URL("http://www.500wan.com/pages/info/datachart/ssq/history/inc/history.php?limit=0&start=09080&end=00000");
  java.net.HttpURLConnection l_connection = (java.net.HttpURLConnection) l_url.openConnection();
  l_connection.connect();
  l_urlStream = l_connection.getInputStream() ;
  java.io.BufferedReader erl_reader = new java.io.BufferedReader(new java.io.InputStreamReader(l_urlStream));
  while ((sCurrentLine = erl_reader.readLine()) != null){
   sTotalString+=sCurrentLine;
  }
  test(sTotalString);
 }
 
 public static void test(String txt){
  String input = txt;
    String exp1 = "[\\s]*[ ]*[\\s]*[ ]*([\\d, -]*)[\\s]*[ ]*[\\s]*[ ]*";
    String  regex = "<tr class=\"t_tr1\"><!--<td>"+exp1+"</td>--><td>"+exp1+"</td><td class=\"t_cfont2\">"+exp1+"</td><td class=\"t_cfont2\">"+exp1+"</td><td class=\"t_cfont2\">"+exp1+"</td><td class=\"t_cfont2\">"+exp1+"</td><td class=\"t_cfont2\">"+exp1+"</td><td class=\"t_cfont2\">"+exp1+"</td><td class=\"t_cfont4\">"+exp1+"</td><td class=\"t_cfont4\">"+exp1+"</td><td>"+exp1+"</td><td>"+exp1+"</td><td>"+exp1+"</td><td>"+exp1+"</td><td>"+exp1+"</td><td>"+exp1+"</td><td>"+exp1+"</td></tr>";

 

   Pattern pattern = Pattern.compile(regex);
   Matcher matcher = pattern.matcher(input);
   while(matcher.find()){
    for(int i=1; i<=matcher.groupCount(); i++){
       System.out.print(matcher.group(i) +"      ");
   }
    System.out.println("");
    }
  
 }
 

}

你可能感兴趣的:(java,.net,PHP)