日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

Java 实现 淘宝秒杀 聚划算 自己主动提醒 源代码

發布時間:2024/4/14 java 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java 实现 淘宝秒杀 聚划算 自己主动提醒 源代码 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

說明

本實例可以監控聚劃算的搶購button,在聚劃算整點聚的時間到達時自己主動彈開頁面(URL自定義)。

能夠自己定義監控持續分鐘數,同一時候還能夠通過多線程加快刷新速度。

源代碼

package com.itechzero.pricemonitor;import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.URI; import java.net.URL; import java.net.URLConnection; import java.text.SimpleDateFormat; import java.util.Date;/*** PriceMonitor.java* * @author Techzero* @Email techzero@163.com* @Time 2014-5-21 下午1:24:30*/ class MyThread extends Thread {public void run() {try {// 此處參數為監控持續分鐘數PriceMonitor.monitorButton(10);} catch (Exception e) {e.printStackTrace();}} };public class PriceMonitor {// 監控的商品URLprivate static String URL = "http://detail.ju.taobao.com/home.htm?

spm=608.2214381.3.1.AdPEjn&item_id=38260927591&id=10000002781939"; // 監視按鈕 public static void monitorButton(int lastMinute) { int nowMinute = Integer.parseInt(new SimpleDateFormat("mm").format(new Date())); int endMinute = Integer.parseInt(new SimpleDateFormat("mm").format(new Date())) + lastMinute; while (nowMinute < endMinute) { nowMinute = Integer.parseInt(new SimpleDateFormat("mm").format(new Date())); String result[] = getCurrentButtonAndForm(URL, "gb2312").split(","); // 當前按鈕狀態 String currentButton = result[0]; // 立即搶 表單 //String form = result[1]; String nowTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); System.out.println(nowTime + " - 如今按鈕是 " + currentButton); if (currentButton == "立即搶" || currentButton.equals("立即搶") || currentButton == "還有機會" || currentButton.equals("還有機會")) { System.out.println("趕緊下單!

"); try { java.awt.Desktop.getDesktop().browse(new URI(URL)); } catch (Exception e) { e.printStackTrace(); } //doPost(form); break; } else if (currentButton == "賣光了" || currentButton.equals("賣光了") || currentButton.equals("已結束") || currentButton.equals("已結束")) { System.out.println("下次再試吧。"); break; } else { System.out.println("還沒開始呢,再等等吧!

"); } } } // 獲取當前按鈕狀態 public static String getCurrentButtonAndForm(String url, String encoding) { if (url == null || "".equals(url.trim())) return null; String buttonState = ""; StringBuffer content = new StringBuffer(); boolean formFlag = false; try { // 新建URL對象 URL u = new URL(url); InputStream is = new BufferedInputStream(u.openStream()); InputStreamReader theHTML = new InputStreamReader(is, encoding != null ? encoding : "gb2312"); BufferedReader br = new BufferedReader(theHTML); String s = ""; while ((s = br.readLine()) != null) { if (s.indexOf("<input type=\"submit\" class=\"buyaction J_BuySubmit\" title=\"立即搶\" value=\"立即搶\"/>") != -1) { buttonState = "立即搶"; } else if (s.indexOf("<a href=\"#\" class=\"extra notice J_BuyButtonSub\">開團提醒</a>") != -1) { buttonState = "開團提醒"; } else if (s.indexOf("<div class=\"main-box chance \">") != -1) { buttonState = "還有機會"; } else if (s.indexOf("<span class=\"out floatright\">賣光了...</span>") != -1) { buttonState = "賣光了"; } else if (s.indexOf("<span class=\"out floatright\">已結束...</span>") != -1) { buttonState = "已結束"; } if (s.indexOf("<form class=\"J_BuySubForm\" data-ccb=\"0\" data-ques=\"0\" action") != -1) { content.append(s + "\r\n"); formFlag = true; } if (formFlag == true) { if (s.indexOf("<input name=\'_tb_token_\' type=\'hidden\' value") != -1) { content.append(s + "\r\n"); } if (s.indexOf("<input type=\"hidden\" name=\"_input_charset\" value") != -1) { content.append(s + "\r\n"); } if (s.indexOf("<input type=\"hidden\" name=\"itemId\" value") != -1) { content.append(s + "\r\n"); } if (s.indexOf("<input type=\"hidden\" name=\"id\" value") != -1) { content.append(s + "\r\n"); } if (s.indexOf("<input type=\"hidden\" name=\"tgType\" value") != -1) { content.append(s + "\r\n"); } if (s.indexOf("<input type=\"submit\" class=\"buyaction J_BuySubmit\"") != -1) { content.append(s + "\r\n"); } if (s.indexOf("</form>") != -1) { content.append(s + "\r\n"); } } if (s.indexOf("<div class=\"time-banner\">") != -1) { break; } } br.close(); } catch (Exception e) { System.err.println(e); return "Open URL Error"; } return buttonState + "," + content; } // 提交表單 public static String doPost(String form) { StringBuffer content = new StringBuffer(); try { URLConnection connection = new URL(URL).openConnection(); connection.setDoOutput(true); OutputStreamWriter os = new OutputStreamWriter(connection.getOutputStream(), "UTF-8"); os.write(form); os.flush(); os.close(); InputStream is = connection.getInputStream(); InputStreamReader theHTML = new InputStreamReader(is); BufferedReader br = new BufferedReader(theHTML); String s = ""; while ((s = br.readLine()) != null) { content.append(s + "\r\n"); } } catch (Exception e) { e.printStackTrace(); } // 返回提交表單后返回的頁面內容 return content.toString(); } // 登錄 public static void doLogin(String username, String password) { String form = "<form id=\"J_StaticForm\" action=\"https://login.taobao.com/member/login.jhtml\" method=\"post\" autocomplete=\"on\"><input type=\"text\" name=\"TPL_username\" id=\"TPL_username_1\" value=\"" + username + "\"><input type=\"password\" name=\"TPL_password\" id=\"TPL_password_1\" value=\"" + password + "\"><input type=\"hidden\" id=\"J_TPL_redirect_url\" name=\"TPL_redirect_url\" value=\"http://www.taobao.com/?

spm=a2107.1.1000340.1.AL2Mpn\"><button type=\"submit\" id=\"J_SubmitStatic\">登 錄</button></form>"; doPost(form); } public static void main(String[] args) { //doLogin(); // new MyThread().start(); // new MyThread().start(); // new MyThread().start(); // new MyThread().start(); // new MyThread().start(); // new MyThread().start(); // new MyThread().start(); new MyThread().start(); } }

總結

以上是生活随笔為你收集整理的Java 实现 淘宝秒杀 聚划算 自己主动提醒 源代码的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。