国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Java教程 - Java實現爬取往期所有雙色球開獎結果功能示例

Java實現爬取往期所有雙色球開獎結果功能示例

2021-05-16 16:43ithouse Java教程

這篇文章主要介紹了Java實現爬取往期所有雙色球開獎結果功能,涉及Java網頁抓取、正則替換、文件讀寫等相關操作技巧,需要的朋友可以參考下

本文實例講述了java實現爬取往期所有雙色球開獎結果功能。分享給大家供大家參考,具體如下:

夢想還是要有的,萬一實現了呢?我相信經常買雙色球的朋友和我都會有一個疑問,就是往期雙色球的開獎結果是什么?我鐘意的這一注雙色球在往期是否開過一等獎,如果開過的話,基本上可以放棄這一注了,因為歷史上應該沒有出現過兩期雙色球開獎完全一致的吧?那么往期的開獎結果是什么呢?我自己用java寫了一個簡易的類,爬取所有雙色球開獎結果,本來想開發安卓版本的,由于ui等需要時間準備,有緣再開發吧。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import java.io.bufferedreader;
import java.io.bufferedwriter;
import java.io.file;
import java.io.filewriter;
import java.io.ioexception;
import java.io.inputstream;
import java.io.inputstreamreader;
import java.net.httpurlconnection;
import java.net.url;
import java.util.regex.matcher;
import java.util.regex.pattern;
import java.util.zip.gzipinputstream;
public class allballs {
 private static stringbuffer mstringbuffer;
 public static void main(string[] args) {
  system.out.println("正在獲取...");
  mstringbuffer = new stringbuffer();
  string baseurlprefix = "http://kaijiang.zhcw.com/zhcw/html/ssq/list_";
  string baseurlsuffix = ".html";
  string homeurl = "http://kaijiang.zhcw.com/zhcw/html/ssq/list_1.html";
  string pagecountcontent = gethtmlstring(homeurl);
  int pagecount = getpagecount(pagecountcontent);
  if (pagecount > 0) {
   for (int i = 1; i <= pagecount; i++) {
    string url = baseurlprefix + i + baseurlsuffix;
    string pagecontent = gethtmlstring(url);
    if (pagecontent != null && !pagecontent.equals("")) {
     getonetermcontent(pagecontent);
    } else {
     system.out.println("第" + i + "頁丟失");
    }
    try {
     thread.sleep(1200);
    } catch (exception e) {
     // todo: handle exception
    }
   }
   file file = new file("雙色球.txt");
   if (file.exists()) {
    file.delete();
   }
   try {
    filewriter writer = new filewriter(file);
    bufferedwriter bufferedwriter = new bufferedwriter(writer);
    bufferedwriter.write(mstringbuffer.tostring());
    bufferedwriter.close();
    writer.close();
   } catch (ioexception e) {
    // todo auto-generated catch block
    e.printstacktrace();
   }
   //bufferedwriter writer = new bufferedwriter(new outputs)
  } else {
   system.out.println("結果頁數為0");
  }
  system.out.println("完成!");
 }
 /**
  * 獲取總頁數
  * @param result
  */
 private static int getpagecount(string result) {
  string regex = "\\d+\">末頁";
  pattern pattern = pattern.compile(regex);
  matcher matcher = pattern.matcher(result);
  string[] splits = null;
  while (matcher.find()) {
   string content = matcher.group();
   splits = content.split("\"");
   break;
  }
  if (splits != null && splits.length == 2) {
   string countstring = splits[0];
   if (countstring != null && !countstring.equals("")) {
    return integer.parseint(countstring);
   }
  }
  return 0;
 }
  /**
  * 獲取網頁源碼
  * @return
  */
 private static string gethtmlstring(string targeturl) {
  string content = null;
  httpurlconnection connection = null;
  try {
   url url = new url(targeturl);
   connection = (httpurlconnection) url.openconnection();
   connection.setrequestmethod("post");
   connection.setrequestproperty("user-agent", "mozilla/4.0 (compatible; msie 7.0; windows 7)");
   connection.setrequestproperty("accept", "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*");
   connection.setrequestproperty("accept-language", "zh-cn");
   connection.setrequestproperty("ua-cpu", "x86");
   //為什么沒有deflate呢
   connection.setrequestproperty("accept-encoding", "gzip");
   connection.setrequestproperty("content-type", "text/html");
   //keep-alive,有什么用呢,你不是在訪問網站,你是在采集。嘿嘿。減輕別人的壓力,也是減輕自己。
   connection.setrequestproperty("connection", "close");
   //不要用cache,用了也沒有什么用,因為我們不會經常對一個鏈接頻繁訪問。(針對程序)
   connection.setusecaches(false);
   connection.setconnecttimeout(6 * 1000);
   connection.setreadtimeout(6 * 1000);
   connection.setdooutput(true);
   connection.setdoinput(true);
   connection.setrequestproperty("charset", "utf-8");
   connection.connect();
   if (200 == connection.getresponsecode()) {
    inputstream inputstream = null;
    if (connection.getcontentencoding() != null && !connection.getcontentencoding().equals("")) {
     string encode = connection.getcontentencoding().tolowercase();
     if (encode != null && !encode.equals("") && encode.indexof("gzip") >= 0) {
      inputstream = new gzipinputstream(connection.getinputstream());
     }
    }
    if (null == inputstream) {
     inputstream = connection.getinputstream();
    }
    bufferedreader reader = new bufferedreader(new inputstreamreader(inputstream, "utf-8"));
    stringbuilder builder = new stringbuilder();
    string line = null;
    while ((line = reader.readline()) != null) {
     builder.append(line).append("\n");
    }
    content = builder.tostring();
   }
  } catch (exception e) {
   e.printstacktrace();
  } finally {
   if (connection != null) {
    connection.disconnect();
   }
  }
  return content;
 }
 private static void getonetermcontent(string pagecontent) {
  string regex = "<td align=\"center\" style=\"padding-left:10px;\">[\\s\\s]+?</em></td>";
  pattern pattern = pattern.compile(regex);
  matcher matcher = pattern.matcher(pagecontent);
  while (matcher.find()) {
   string onetermcontent = matcher.group();
   getonetermnumbers(onetermcontent);
  }
 }
 private static void getonetermnumbers(string onetermcontent) {
  string regex = ">\\d+<";
  pattern pattern = pattern.compile(regex);
  matcher matcher = pattern.matcher(onetermcontent);
  while (matcher.find()) {
   string content = matcher.group();
   string ballnumber = content.substring(1, content.length()-1);
   mstringbuffer.append(ballnumber).append(" ");
  }
  mstringbuffer.append("\r\n");
 }
}

運行結果:

Java實現爬取往期所有雙色球開獎結果功能示例

希望本文所述對大家java程序設計有所幫助。

原文鏈接:https://blog.csdn.net/ithouse/article/details/50908296

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 久久精品a一级国产免视看成人 | 91在线你懂的 | 欧美视频免费看 | 午夜视频免费 | 天天操天天干天天爽 | 国产视频亚洲 | 亚洲精品乱码久久久久久蜜桃不爽 | 国产第一区在线观看 | 国产精品九九九 | 欧美日韩高清一区 | 精品亚洲国产成av人片传媒 | 黄色电影在线免费观看 | 日韩亚洲 | 久久久中文字 | 黄色在线观看视频 | 亚洲精品一 | 国产成人在线视频 | 欧美a一级 | 午夜影院网站 | 日韩一区在线观看视频 | 日韩中文字幕在线播放 | 成人午夜精品视频 | 亚洲va| 日韩一区二区在线观看 | 在线观看一区二区三区四区 | 久久久久综合狠狠综合日本高清 | 草久网 | 天天爽夜夜爽夜夜爽精品视频 | 国产一区二区久久 | 日韩免费高清视频 | 特级黄一级播放 | 久久av一区二区三区 | 天天天操 | 日韩精品在线视频 | 久久精品2019中文字幕 | 免费在线观看一区二区 | 国产精品a久久 | 欧美第8页 | 特污影院| 亚洲成人精品一区 | 久久精品国产精品青草 |