説明します
この例では、Juhuasuanのスナップアップボタンを監視し、Juhuasuanの全ポイント収集の時間が到着したときにページを自動的にポップアップします(URLはそれ自体で定義されます)。
過去数分の監視をカスタマイズし、マルチスレッドでリフレッシュ速度を高速化することもできます。
ソースコード
パッケージcom.itechzero.pricemonitor; java.io.bufferedinputStreamをインポートします。 java.io.bufferedreaderをインポートします。 java.io.inputStreamReaderをインポートします。 java.io.inputStreamReaderをインポートします。 java.io.outputStreamWriterをインポートします。 java.net.uriをインポートします。 java.net.urlをインポートします。 java.net.urlconnectionをインポートします。 java.text.simpledateformatをインポートします。 Import Java.util.date; / ** * pricemonitor.java * * @author techzero * @email [email protected] * @time 2014-5-21 1:24:30 pm */ class mythread extends thread {public void run(){//パラメーターはPricemonitorの監視の数です。 } catch(Exception e){e.printstacktrace(); }}}}; public class pricemonitor {//監視されている製品URLプライベート静的文字列url = "http://detail.ju.taobao.com/home.htm?spm=608.2214381.3.1.Adpejn&item_id=38260927591&id10000002781939" //監視ボタン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")。形式(new date())); string result [] = getCurrentButtonAndform(url、 "gb2312")。split( "、"); //現在のボタンステータス文字列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 == "get now" || currentButton.equals( "get now")|| currentButton == "get now" || currentButton.equals( "get now")){system.out.println( "get now!"); try {java.awt.desktop.getdesktop()。browse(new uri(url)); } catch(Exception e){e.printstacktrace(); } // dopost(form);壊す; } else if(currentButton == "売り切れ" || currentButton.equals( "sold out")|| currentButton.equals( "ended")|| currentButton.equals( "Ended")){system.out.println( "次回に再試行!");壊す; } else {system.out.println( "まだ開始されていない、待ってください!"); }}} //現在のボタンステータスを取得しますpublic static static string getCurrentButtonAndform(string url、string encoding){if(url == null || "" .equals(url.trim()))null;文字列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);文字列s = ""; while((s = br.readline())!= null){if(s.indexof( "<input type =/" submit/"class =/" buyaction j_buysubmit/"title =/" grab/"value =/" grab/"/>")!= -1){buttonState = "grab/"; } else if(s.indexof( "<a href =/"#/"class =/" extra nocation j_buybuttonsub/">チームオープニングリマインダー</a>") } else if(s.indexof( "<div class = /" Main -Box Chance /">") } else if(s.indexof( "<span class =/" out floatright/">売り切れ... </span>") } else if(s.indexof( "<span class =/" out floatright/"> ended ... </span>")!= -1){buttonState = "ended"; } 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 =/" 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 =/"購入j_buysubmit/"")!= -1){content.append(s + "/r/n"); } if(s.indexof( "<div class =/" time -banner/">")!= -1){content.append(s + "/r/n"); }} if(s.indexof( "<div class =/" time -banner/">")!= -1){break; }} br.close(); } catch(Exception e){System.err.println(e); 「urlエラーを開く」を返します。 } buttonState + "、" + contentを返します。 } //フォームを提出しますpublic static string dopost(string form){stringbuffer content = new StringBuffer(); {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);文字列s = ""; while((s = br.readline())!= null){content.append(s + "/r/n"); }} catch(例外e){e.printstacktrace(); } // form 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 =/" tppl_us/"/"> "post/" tppner id =/"tpl_username_1/" value =/"" + username + "/"> <input type =/"name/" name =/"tpl_password/" id =/"tpl_password_1/" " +" + "/"> <inputタイプ=/"hiddder/" id =/"j_tpl_redect_url/" tppl_url/"tppl_url/" tppl_url value =/"http://www.taobao.com/?spm=a2107.1.1000340.1.al2mpn/"> <button type =/"submit/" id =/"j_submitstatic/"> login </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(); }}
上記はこの記事のすべての内容です。みんなの学習に役立つことを願っています。誰もがwulin.comをもっとサポートすることを願っています。