Chinaunix首页 | 论坛 | 博客
  • 博客访问: 146338
  • 博文数量: 39
  • 博客积分: 993
  • 博客等级: 准尉
  • 技术积分: 335
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-14 16:36
个人简介

https://github.com/dengdaiyemanren

文章分类

全部博文(39)

文章存档

2015年(1)

2012年(3)

2011年(27)

2010年(4)

2008年(4)

分类: Java

2012-05-13 18:56:42

最近分析双色球的出现概率,首先需要获取基础数据,这是一个从现有彩票网站获取数据的方法,
很简单的一段代码,就不解释了。

点击(此处)折叠或打开

  1. import java.io.IOException;

  2. import org.jsoup.Jsoup;
  3. import org.jsoup.nodes.Document;
  4. import org.jsoup.nodes.Element;
  5. import org.jsoup.select.Elements;
  6. import org.springframework.context.ApplicationContext;
  7. import org.springframework.context.support.FileSystemXmlApplicationContext;

  8. import persist.dao.NickAtomBeanDao;
  9. import persist.domain.InfNickDataValue;

  10. public class QueryHtmlAndSaveData {

  11.     public static void main(String[] args) {
  12.         // TODO Auto-generated method stub
  13.         // File input = new File("D:\\curlexe\\caipiap.html");
  14.         Document doc;
  15.         try {
  16.             /*
  17.              * doc = Jsoup.parse(input, "UTF-8",
  18.              * "!ssqjbzs.jhtml?flag=jbzs");
  19.              */

  20.             doc = Jsoup
  21.                     .connect(
  22.                             "!ssqjbzs.jhtml?flag=jbzs&a1=on&b1=on&checkbox=checkbox&checkbox2=checkbox&checkbox3=checkbox&maxsize=3000&openDate=&sortTag=up&statisticsTag=1")
  23.                     .get();

  24.             Element content = doc.getElementById("tdata");
  25.             // System.out.println(content.toString());
  26.             Elements trtag = content.getElementsByTag("tr");

  27.             ApplicationContext ctx = new FileSystemXmlApplicationContext(
  28.                     new String[] { "src/persist/nick-data.xml",
  29.                             "src/persist/sql-map-config.xml",
  30.                             // "src/persist/usermap-sql.xml",
  31.                             "src/persist/nick-data-ibtatis.xml" });
  32.             NickAtomBeanDao nickDataDao = (NickAtomBeanDao) ctx
  33.                     .getBean("nickDataDao");

  34.             int i = 1;
  35.             for (Element tritem : trtag) {

  36.                 InfNickDataValue infNickDataValue = new InfNickDataValue();

  37.                 Element time = tritem.getElementsByTag("td").first();

  38.                 Elements td = tritem.getElementsByClass("chartBall01");

  39.                 if (td.size() == 0) {
  40.                     continue;
  41.                 }

  42.                 Element blue = tritem.getElementsByClass("chartBall02").get(0);
  43.                 // System.out.print(time.text().toString());

  44.                 String nick = new String();
  45.                 for (int j = 0; j < td.size(); j++) {

  46.                     Element tditem = td.get(j);
  47.                     Integer value = Integer.valueOf(tditem.text().toString());

  48.                     switch (j) {
  49.                     case 0:
  50.                         infNickDataValue.setOne(value);
  51.                         break;
  52.                     case 1:
  53.                         infNickDataValue.setTwo(value);
  54.                         break;
  55.                     case 2:
  56.                         infNickDataValue.setThree(value);
  57.                         break;
  58.                     case 3:
  59.                         infNickDataValue.setFour(value);
  60.                         break;
  61.                     case 4:
  62.                         infNickDataValue.setFive(value);
  63.                         break;
  64.                     case 5:
  65.                         infNickDataValue.setSix(value);
  66.                         break;
  67.                     default:
  68.                         break;
  69.                     }

  70.                     // nick = nick + " " + tditem.text().toString();
  71.                 }
  72.                 // System.out.print(nick);
  73.                 // System.out.println("|" + blue.text().toString());

  74.                 infNickDataValue.setLinecol(i);// lineCol
  75.                 infNickDataValue.setQs(Integer.valueOf(time.text().toString()));
  76.                 infNickDataValue.setLuckno(Integer.valueOf(blue.text()
  77.                         .toString()));

  78.                 nickDataDao.saveInfNickData(infNickDataValue);
  79.                 i++;

  80.             }

  81.             System.out.println("qu===" + i);
  82.         } catch (IOException e) {
  83.             e.printStackTrace();
  84.         }

  85.     }
  86. }

阅读(5306) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

认真的鱼1232012-05-14 21:59:45

恩,这个代码很简单