설명
이 예제는 Juhuasuan의 스냅 업 버튼을 모니터링하고 Juhuasuan의 전체 포인트 수집 시간이 도착하는 경우 (URL 자체로 정의 됨) 페이지를 자동으로 팝업 할 수 있습니다.
지난 몇 분의 모니터링을 사용자 정의하고 멀티 스레딩을 통해 새로 고침 속도를 높일 수도 있습니다.
소스 코드
패키지 com.itechzero.pricemonitor; import java.io.bufferedInputStream; import java.io.bufferedReader; import java.io.inputStreamReader; 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 [email protected] * @time 2014-5-21 PM */ 클래스 Mythread는 스레드 {public void run () {// 여기 매개 변수가 precemonitor.monitorbutton (10)의 모니터링 분수 수입니다. } catch (예외 e) {e.printstacktrace (); }}}}; 공개 클래스 프리 메이터 {// 모니터링 된 제품 URL 비공개 정적 문자열 URL = "http://detail.ju.taobao.com/home.htm?spm=608.2214381.3.1.adpejn&item_id=38260927591&id=100002781939"; // 모니터링 버튼 공개 정적 무효 모니터 버튼 (int lastminute) {int nowminute = integer.parseint (new SimpledateFormat ( "mm"). 형식 (new Date ()); int endminute = integer.parseint (new simpledateformat ( "mm"). 형식 (new date ()) + lastminute; while (nowminute <endminute) {nowminute = integer.parseint (new simpledateformat ( "mm"). 형식 (new date ()); 문자열 result [] = getCurrentButtonAndform (url, "gb2312"). split ( ","); // 현재 버튼 상태 문자열 currentButton = result [0]; // 즉시 양식을 잡습니다. // 문자열 양식 = 결과 [1]; 문자열 nowtime = new simpledateformat ( "yyyy-mm-dd hh : mm : ss"). 형식 (new date ()); System.out.println (nowtime + " - 이제 버튼은" + currentButton); if (currentButton == "get now"|| currentButton.equals ( "지금 지금") || currentButton == "지금 얻기"|| currentButton.equals ( "지금")) {system.out.println ( "지금!"); try {java.awt.desktop.getdesktop (). 찾아보기 (new uri (url)); } catch (예외 e) {e.printstacktrace (); } // dopost (form); 부서지다; } else if (currentButton == "매진"|| currentButton.equals ( "매진") || currentButton.equals ( "ended") || currentbutton.equals ( "ended")) {system.out.println ( "다음에 다시 시도하십시오!"); 부서지다; } else {system.out.println ( "아직 시작되지 않았다, 기다려!"); }}} // 현재 버튼 상태 가져 오기 공개 정적 문자열 getCurrentButtonAndForm (String URL, String Encoding) {if (url == null || "".equals (url.trim ())) return null; 문자열 buttonstate = ""; StringBuffer content = new StringBuffer (); 부울 formflag = false; try {// 새 URL 객체 생성 URL u = new URL (url); inputStream은 = 새로운 bufferedInputStream (u.openStream ()); inputStreamReader thehtml = new inputStreamReader (is, encoding! = null? 인코딩 : "gb2312"); bufferedReader br = new bufferedReader (html); 문자열 s = ""; while ((s = br.readline ())! = null) {if ( "<input type =/"제출/"class =/"구매 j_buysubmit/"title =/"grab/"value =/"grab/"/>") {buttonstate = "grab/"; } else if ( "<a href =/"#/"class =/"추가 통지 j_buybuttonsub/"> 팀 오프닝 알림 </a>")! = -1) {buttonstate = "팀 오프닝 알림"; } else if ( "<div class = /"main -box rance /">")! = -1) {buttonstate = "매진"; } else if (s.indexof ( "<span class =/"out floatright/"> 매진 ... </span>")! = -1) {buttonstate = "매진"; } 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 =/"class/"class =/"구매 j_buysubmit/"")! = -1) {content.append (s + "/r/n"); } if (s.indexof ( "<div class =/"time -banner/">")! = -1) {content.append (s + "/r/n"); }} if ( "<div class =/"time -banner/">")! = -1) {break; }} br.close (); } catch (예외 e) {System.err.println (e); "URL 오류 열기"를 반환합니다. } return buttonstate + "," + 컨텐츠; } // 양식 공용 정적 문자열 dopost (문자열 양식) {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은 = connection.getInputStream (); inputStreamReader thehtml = new inputStreamReader (IS); bufferedReader br = new bufferedReader (html); 문자열 s = ""; while ((s = br.readline ())! = null) {content.append (s + "/r/n"); }} catch (예외 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/"autoconmplete =/"intput type =/"text/"text/"text/"text/"text/"text/"text/"text/"text/"text/"text/"text/"text/"text/"text/"text type =/"method =/"autocomplete =/" id =/"tpl_username_1/"value =/"" " + username +"/"> <input type =/"password/"name =/"tpl_password/"id =/"tpl_password_1/"value =/" " + password +"/"/"/"hidden/"id =/"j_tpl_rect/"tpl_rect/"tpl_Rect _RECT _RECT_RECT value =/"http://www.taobao.com/?spm=a2107.1000340.1.al2mpn/"> <버튼 유형 =/"제출/"id =/"j_submitstatic/"> login </button> </form> "; dopost (형태); } public static void main (String [] args) {// dologin (); // new Mythread (). start (); // new Mythread (). start (); // new Mythread (). start (); // new Mythread (). start (); // new Mythread (). start (); }}
위는이 기사의 모든 내용입니다. 모든 사람의 학습에 도움이되기를 바랍니다. 모든 사람이 wulin.com을 더 지원하기를 바랍니다.