ilustrar
Este ejemplo puede monitorear el botón de inicio de Juhuasuan y aparecer automáticamente la página cuando llega la hora de la recolección de puntos completo de Juhuasuan (la URL se define por sí misma).
Puede personalizar el monitoreo de los últimos minutos y también acelerar la velocidad de actualización a través de la lectura múltiple.
Código fuente
paquete com.itechzero.picemonitor; 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 1:24:30 pm */ class myThread extiende el hilo {public void run () {try {// El parámetro aquí es el número de minutos de monitorear priconitor.monitorbutton (10); } catch (Exception e) {E.PrintStackTrace (); }}}}; Public Class Pricemonitor {// La url de producto monitoreado Cadena estática privada url = "http://detail.ju.taobao.com/home.htm?spm=608.2214381.3.1.adpejn&item_id=3820927591&id=10000002781939"; // Botón de monitoreo public static void monitorButton (int LastMinute) {int NowMinute = Integer.ParseInt (new SimpleDateFormat ("mm"). Format (nuevo date ())); int endMinute = Integer.ParseInt (new SimpleDateFormat ("MM"). Format (New Date ())) + LastMinute; while (NowMinute <endMinute) {NowMinute = Integer.ParseInt (new SimpleDateFormat ("mm"). Format (nuevo date ())); Resultado de cadena [] = getCurrentButtonAndForm (url, "GB2312"). Split (","); // Estado del botón actual Cadena CurrentButton = resultado [0]; // Agarra el formulario inmediatamente // String Form = resultado [1]; String NowTime = new SimpleDateFormat ("yyyyy-mm-dd hh: mm: ss"). Format (nueva fecha ()); System.out.println (ahora tiempo + " - ahora el botón es" + CurrentButton); if (currentButton == "Get Now" || CurrentButton.equals ("Get Now") || CurrentButton == "Get Now" || CurrentButton.equals ("Get Now")) {System.out.println ("Get Now!"); intente {java.awt.desktop.getdesktop (). BROWSE (nuevo URI (URL)); } catch (Exception e) {E.PrintStackTrace (); } // dopost (forma); romper; } else if (currentButton == "Volcado" || CurrentButton.equals ("Sellado") || CurrentButton.equals ("finalizado") || CurrentButton.equals ("finalizado"))) {System.out.println ("Intente nuevamente la próxima vez!"); romper; } else {System.out.println ("¡No se inició todavía, espera!"); }}} // Obtener el estado del botón actual public Static String getCurrentButtonAndform (String url, codificación de cadena) {if (url == null || "" .equals (url.trim ())) return null; String ButtonState = ""; StringBuffer content = new StringBuffer (); boolean formflag = false; Pruebe {// cree nuevo objeto URL url u = new url (url); InputStream es = new BufferedInputStream (U.OpenStream ()); InputStreamReader thehtml = new InputStreamReader (es, codificación! = NULL? Codificación: "GB2312"); BufferedReader BR = New BufferedReader (thehtml); Cadena S = ""; while ((s = br.readline ())! = null) {if (s.indexof ("<input type =/" subt/"class =/" buyation j_buyysubmit/"title =/" grab/"value =/" grab/"/>")! = -1) {ButtonState = "Grab/"; } else if (s.indexof ("<a href =/"#/"class =/" Aviso adicional J_BuyButtonSub/"> Recordatorio de apertura del equipo </a>")! = -1) {ButtonState = "Recordatorio de apertura del equipo"; } else if (s.indexof ("<div class = /" main -box Chance /">")! = -1) {buttonState = "vendido"; } else if (s.indexof ("<span class =/" out floatright/"> agotado ... </span>")! = -1) {buttonState = "vendido"; } else if (s.indexof ("<span class =/" out floatright/"> finalizado ... </span>")! = -1) {ButtonState = "Ended"; } if (s.indexof ("<form class =/" j_buyysubform/"data-ccb =/" 0/"data-ques =/" 0/"acción")! = -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/"valor")! = -1) {content.append (s + "/r/n"); } if (s.indexof ("<input type =/" Hidden/"name =/" itemID/"valor")! = -1) {content.append (s + "/r/n"); } if (s.indexof ("<input type =/" Hidden/"name =/" id/"valor")! = -1) {content.append (s + "/r/n"); } if (s.indexof ("<input type =/" Hidden/"name =/" id/"valor")! = -1) {content.append (s + "/r/n"); } if (s.indexof ("<input type =/" Hidden/"name =/" tgtype/"valor")! = -1) {content.append (s + "/r/n"); } if (s.indexof ("<input type =/" subt/"class =/" buyation j_buyysubmit/"")! = -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 (excepción e) {system.err.println (e); devolver "Error de URL abierto"; } return ButtonState + "," + contenido; } // Enviar el formulario public static string dopost (formulario de cadena) {stringBuffer content = new StringBuffer (); intente {urlconnection Connection = new URL (url) .openconnection (); Connect.SetDoOutput (verdadero); OutputStreamWriter OS = new OuttreStreamWriter (conexión.getOutputStream (), "UTF-8"); OS.Write (formulario); OS.Flush (); os.close (); InputStream IS = Connection.getInputStream (); InputStreamReader thehtml = new InputStreamReader (is); BufferedReader BR = New BufferedReader (thehtml); Cadena S = ""; while ((s = br.readline ())! = null) {content.append (s + "/r/n"); }} catch (Exception e) {E.PrintStackTrace (); } // Devuelve el contenido de la página devuelto después de enviar el formulario return content.toString (); } // Iniciar sesión en public static void dologin (String UserName, String Password) {String Form = "<Form ID =/" J_StaticForm/"Action =/" https://login.taobao.com/member/login.jhtml/ "método =/" post/"autocomplette =/" on/"> <input type =/" text/"name ty/" name " id =/"tpl_username_1/" value =/"" + UserName + "/"> <input type =/"contraseña/" name =/"tpl_password/" id =/"tpl_password_1/" valor =/"" + contraseña + "/"> <input =/"Hidden/" id =/"j_tpl_redirect_url/" name =/"tplil valor =/"http://www.taobao.com/?spm=a2107.1.1000340.1.al2mpn/"> <button type =/"shit/" id =/"j_submitstatic/"> Login </Button> </form> "; dopost (forma); } public static void main (string [] args) {// dologin (); // nuevo MyThread (). Start (); // nuevo MyThread (). Start (); // nuevo MyThread (). Start (); // nuevo MyThread (). Start (); // nuevo MyThread (). Start (); }}
Lo anterior es todo el contenido de este artículo. Espero que sea útil para el aprendizaje de todos y espero que todos apoyen más a Wulin.com.