zoukankan      html  css  js  c++  java
  • 双色球2013年统计,从网上爬虫出来的

    package com.hpu.bai;
    
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.Writer;
    import java.net.URL;
    
    import org.jsoup.Jsoup;
    import org.jsoup.nodes.Document;
    import org.jsoup.nodes.Element;
    import org.jsoup.select.Elements;
    
    public class Double2013 {
    	public static void main(String[] args) throws Exception {
    		Document doc;
    		File file = new File("d:\双色球第2013015期到2013154期开奖结果.txt");
    		FileOutputStream fos = new FileOutputStream(file); 
    		//while(true){
    			for(int i = 2013015;i<=2013154;i++){
    			String url = "http://caipiao.163.com/award/ssq/"+i+".html";
    			doc  = (Document) Jsoup.connect(url).get();
    			//String title = doc.title();
    			//Elements ele = doc.select("div.search_zj_left p.red_ball span");
    			Element content = doc.getElementById("zj_area");
    			Elements links = content.getElementsByTag("span");
    			//System.out.println(links.size());
    			int count =0;byte[] b = new byte[1024];
    			for (Element link : links) {  
    				count++;
    				//String linkHref = link.attr("href");  
    				String linkText = link.text();
    				//System.out.print(linkHref);
    				System.out.print(" "+linkText);	
    				//linkText.toCharArray();
    				linkText = " "+linkText;
    				 b = linkText.getBytes();
    				fos.write(b);
    				if(count%7 == 0){
    					fos.write("
    ".getBytes());
    				}
    				}
    				System.out.println();
    			//String ball = ele.text();
    			/*Element dayFav = doc.getElementsByAttributeValue("class", "linkRight").first(); 
    			Elements dayFavItems = dayFav.getElementsByTag("a"); 
    			for (Element dayFavItem:dayFavItems) { 
    				System.out.println(dayFavItem.text()); 
    			} */
    			//System.out.println(title);
    			//System.out.println(ball);
    			Thread.sleep(1500);
    			}
    		//}
    	fos.flush();fos.close();
    	}
    }
    

    其中用到了jsoup的东西,具体的还不太会用。QQ:623687677

  • 相关阅读:
    ASP.NET小知识
    追溯ASP.NET发展史
    《ASP.NET MVC4 WEB编程》学习笔记------UrlHelper
    Python数据分析8-----网页文本处理
    sklearn学习9----LDA(discriminat_analysis)
    树(8)----路径和
    树(7)-----二叉树的序列化和反序列化
    xgboost学习
    Python笔记24-----迭代器、生成器的使用(如嵌套列表的展开、树的遍历等)
    算法20-----卡诺兰数
  • 原文地址:https://www.cnblogs.com/neruda/p/4025504.html
Copyright © 2011-2022 走看看