Lab grab number Artifact

Source: Internet
Author: User
Tags set cookie

 PackageStep1;ImportJava.util.Calendar;Importorg.apache.commons.httpclient.HttpClient;ImportOrg.apache.commons.httpclient.methods.GetMethod;/*** * @ClassName: Quhao * @Description: Lab Grab number Artifact *@authorZeze * @date November 10, 2015 PM 2:51:31 **/ Public classQuhao {Private Static inthour; Private Static intminute; Private Static intsecond; Private StaticCalendar C; Private StaticString Url = "Http://219.229.132.37:8080/AjaxService/qh.ashx"; Private StaticString cookie = "ASP.NET_SESSIONID=12PEDXYGGBPF3X2V1KG0XV55";//pre-set cookie value    Private Static intSleeptime = 10;//set the refresh rate, per millisecond     Public Static voidMain (string[] args)throwsinterruptedexception {//wait for the ticket time, the refresh time is 60S         while(true) {settime ();//Get current Time//start robbing time 8:18 or 11:58            if(Hour = = 8 && Minute >= | | hour = && minute >= 58)                 Break; System.out.println (Hour+ ":" + Minute + ":" + Second + "Now is not the time period of the robbery. Please, later ... "); Thread.Sleep (30000);//30S Refresh Time        }        intCount = 1; //start stealing tickets .         while(true) {settime (); System.out.println ("Current number of numbers" + Count + "times" + Hour + ":" + Minute + ":" +second);            Func (); Thread.Sleep (Sleeptime); //Request time intervalcount++; if(Hour = = 8 && Minute >= | | hour = && minute >= 10) {System.out.println ("This is the end of the round.");  Break; }        }    }    Private Static voidfunc () {HttpClient HttpClient=NewHttpClient (); Try{GetMethod GetMethod=NewGetMethod (URL); Getmethod.getparams (). Setcontentcharset ("Utf-8"); //a cookie is required for each visit to the URL to be authorizedGetmethod.setrequestheader ("Cookie", cookies); Getmethod.setrequestheader ("Accept-language", "ZH-CN"); Getmethod.setrequestheader ("User-agent", "mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; trident/6.0) qqbrowser/9.2.5063.400 "); intStatusCode = Httpclient.executemethod (GetMethod);//return status Code 200 for success, 500 for server-side run errorSystem.out.println ("Return Status code:" +StatusCode); //print out the return data and verify the successString result =getmethod.getresponsebodyasstring (); if(StatusCode = = 500) System.out.println ("Server error occurred"); ElseSystem.out.println (Result); }        Catch(Exception e) {e.printstacktrace (); }    }    Private Static voidSetTime () {//Get current Timec =calendar.getinstance (); Hour=C.get (Calendar.hour_of_day); Minute=C.get (Calendar.minute); Second=C.get (Calendar.second); }}

Python version:

#-*-coding:utf-8-*-ImportUrllib2Import TimedefQuhao (): URL="http://219.229.132.37:8080/AjaxService/qh.ashx"send_headers={"Accept":"*/*",            "Referer":"http://219.229.132.37:8080/Default.aspx",            "Accept-language":"ZH-CN",            "accept-encoding":"gzip, deflate",            "user-agent":"mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; trident/6.0) qqbrowser/9.2.5063.400",            "Host":"219.229.132.37:8080",} Cookies="Asp.net_sessionid=ff3uelme0mj1uwnqcfegfrup;"send_headers['Cookies']=Cookies req= Urllib2. Request (url,headers=send_headers) R=Urllib2.urlopen (req) HTML=r.read () HTML= Html.decode ('Utf-8','Replace')    returnHTMLPrintQuhao () timestruct=time.localtime () while( not((timestruct.tm_hour==8 andTimestruct.tm_min>17 andTIMESTRUCT.TM_MIN&LT;25)or((timestruct.tm_hour==11 andTIMESTRUCT.TM_MIN&GT;57)or(timestruct.tm_hour==12 andTimestruct.tm_min<5)))):    PrintU"It's not time to rob the ticket ."    PrintTime.strftime ('%y-%m-%d%h:%m:%s') Time.sleep (60) Timestruct=time.localtime () timestruct=time.localtime () Count=1if((timestruct.tm_hour==8 andTimestruct.tm_min>17 andTIMESTRUCT.TM_MIN&LT;25)or((timestruct.tm_hour==11 andTIMESTRUCT.TM_MIN&GT;58)or(timestruct.tm_hour==12 andTimestruct.tm_min<5))):     while(True):Try: HTML=Quhao ()PrintHTML Time.sleep (0.3)            PrintU"is trying the first"+str (count) +u"time to collect tickets"Count=count+1ifcount>1000: Input_raw ()exceptException, E:PrinteElse:    PrintU"not within the time period of the ticket pickup"    

Lab grab number Artifact

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.