Java实现淘宝秒杀聚划算抢购自动提醒源码
说明
本实例能够监控聚划算的抢购按钮,在聚划算整点聚的时间到达时自动弹开页面(URL自己定义)。
可以自定义监控持续分钟数,同时还可以通过多线程加快刷新速度。
源码
packagecom.itechzero.pricemonitor; importjava.io.BufferedInputStream; importjava.io.BufferedReader; importjava.io.InputStream; importjava.io.InputStreamReader; importjava.io.OutputStreamWriter; importjava.net.URI; importjava.net.URL; importjava.net.URLConnection; importjava.text.SimpleDateFormat; importjava.util.Date; /** *PriceMonitor.java * *@authorTechzero *@Emailtechzero@163.com *@Time2014-5-21下午1:24:30 */ classMyThreadextendsThread{ publicvoidrun(){ try{ //此处参数为监控持续分钟数 PriceMonitor.monitorButton(10); }catch(Exceptione){ e.printStackTrace(); } } }; publicclassPriceMonitor{ //监控的商品URL privatestaticStringURL="http://detail.ju.taobao.com/home.htm?spm=608.2214381.3.1.AdPEjn&item_id=38260927591&id=10000002781939"; //监视按钮 publicstaticvoidmonitorButton(intlastMinute){ intnowMinute=Integer.parseInt(newSimpleDateFormat("mm").format(newDate())); intendMinute=Integer.parseInt(newSimpleDateFormat("mm").format(newDate()))+lastMinute; while(nowMinute")!=-1){ buttonState="马上抢"; }elseif(s.indexOf(" 开团提醒")!=-1){ buttonState="开团提醒"; }elseif(s.indexOf(" ")!=-1){ buttonState="还有机会"; }elseif(s.indexOf(" 卖光了...")!=-1){ buttonState="卖光了"; }elseif(s.indexOf(" 已结束...")!=-1){ buttonState="已结束"; } if(s.indexOf(" ")!=-1){ content.append(s+"\r\n"); } } if(s.indexOf(" ")!=-1){ break; } } br.close(); }catch(Exceptione){ System.err.println(e); return"OpenURLError"; } returnbuttonState+","+content; } //提交表单 publicstaticStringdoPost(Stringform){ StringBuffercontent=newStringBuffer(); try{ URLConnectionconnection=newURL(URL).openConnection(); connection.setDoOutput(true); OutputStreamWriteros=newOutputStreamWriter(connection.getOutputStream(),"UTF-8"); os.write(form); os.flush(); os.close(); InputStreamis=connection.getInputStream(); InputStreamReadertheHTML=newInputStreamReader(is); BufferedReaderbr=newBufferedReader(theHTML); Strings=""; while((s=br.readLine())!=null){ content.append(s+"\r\n"); } }catch(Exceptione){ e.printStackTrace(); } //返回提交表单后返回的页面内容 returncontent.toString(); } //登录 publicstaticvoiddoLogin(Stringusername,Stringpassword){ Stringform=" 登录"; doPost(form); } publicstaticvoidmain(String[]args){ //doLogin(); //newMyThread().start(); //newMyThread().start(); //newMyThread().start(); //newMyThread().start(); //newMyThread().start(); //newMyThread().start(); //newMyThread().start(); newMyThread().start(); } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。