刷票系统(微信人工投票10元1000票) 一、前言 相信大家平时肯定会收到朋友发来的链接,打开一看,哦,需要投票。投完票后弹出一个页面(恭喜您,您已经投票成功),再次点击的时候发现,啊哈,您的IP(。。。)已经投过票了,不能重复投票。这时候,我们可能会想,能不能突破ip地址的限制进行刷票呢?有了这样的想法,那就去做吧,下面我将介绍我这个简单的刷票系统,仅供有需求的园友们参考。 二、系统设计 系统主要实现的是突破IP限制进行刷票,其中,由IP采集模块负责从互联网上爬取代理IP,放入阻塞队列,该任务会定期执行。之后由投票模块从阻塞队列中获取IP,并进行设置,然后进行投票。系统流程图如下: 三、系统技术 系统使用HttpClientJSoup多线程来完成刷票,HttpClient用于进行投票,JSoup用于解析页面,多线程技术用于分离任务,使得分工更加明确。使用到了生产者消费者模式,该模式直接使用BlockingQueue来实现。 四、系统介绍 系统主要分为三个模块: IP采集模块 投票模块 IP信息模块 其中,IP采集模块主要是从互联网爬取IP代理信息,并将该信息放入阻塞队列,这样就可以伪造IP,进行多次投票。 其中,投票模块从IP采集模块放入阻塞队列取出IP信息,并设置代理,找到投票入口地址,然后进行投票操作。 其中,IP信息模块主要是对爬取的IP信息进行了封装,方便其他模块进行操作。 4。1IP采集模块 IP采集模块流程图如下 几点说明: 1。系统使用的代理IP站点URL为http:www。kuaidaili。com,www。xicidaili。com。 2。提取IP信息为提取单条IP信息,并判断历史IP表是否已经存在,若存在,表示之前已经加入过此IP信息,则直接丢弃,反之,则加入队列并加入历史IP表。 3。此任务会定期开启,如一个小时爬取一次代理IP。 4。2投票模块 投票模块流程图如下 几点说明: 1。投票网站 http:www。hnxdf。comvote,我们选取的第一位进行投票,分析出投票的入口为http:www。hnxdf。comvoteiRadiovote。asp?VoTeid215。 2。根据IP采集模块放入队列的IP信息进行设置,然后进行投票。 4。3IP信息模块 此模块主要对从网站爬取的IP信息进行了封装,方便其他模块进行操作。 五、系统代码框架 系统的整个代码框架如下 其中,bean包的IpInfo封装了爬取的IP信息。 其中,entrance包的Vote为系统的入口。 其中,thread包的IPCollectTask为爬取代理IP任务,VoteThread为进行投票线程。 六、系统代码 1。IpInfo。javapackagecom。hust。grid。leesf。bean;publicclassIpInfo{publicIpInfo(StringipAddress,intport,Stringlocation,StringanonymousType,Stringtype,StringconfirmTime){this(ipAddress,port,location,anonymousType,type,confirmTime,null,null);}publicIpInfo(StringipAddress,intport,Stringlocation,StringanonymousType,Stringtype,StringconfirmTime,StringgetPostSupport,StringresponseSpeed){this。ipAddressipAddress;this。portport;this。locationlocation;this。anonymousTypeanonymousType;this。typetype;this。confirmTimeconfirmTime;this。getPostSupportgetPostSupport;this。responseSpeedresponseSpeed;}publicStringgetIpAddress(){returnipAddress;}publicvoidsetIpAddress(StringipAddress){this。ipAddressipAddress;}publicintgetPort(){returnport;}publicvoidsetPort(intport){this。portport;}publicStringgetLocation(){returnlocation;}publicvoidsetLocation(Stringlocation){this。locationlocation;}publicStringgetAnonymousType(){returnanonymousType;}publicvoidsetAnonymousType(StringanonymousType){this。anonymousTypeanonymousType;}publicStringgetType(){returntype;}publicvoidsetType(Stringtype){this。typetype;}publicStringgetConfirmTime(){returnconfirmTime;}publicvoidsetConfirmTime(StringconfirmTime){this。confirmTimeconfirmTime;}publicStringgetGetPostSupport(){returngetPostSupport;}publicvoidsetGetPostSupport(StringgetPostSupport){this。getPostSupportgetPostSupport;}publicStringgetResponseSpeed(){returnresponseSpeed;}publicvoidsetResponseSpeed(StringresponseSpeed){this。responseSpeedresponseSpeed;}Overridepublicbooleanequals(Objectanthor){if(thisanthor){returntrue;}if(anthornullgetClass()!anthor。getClass()){returnfalse;}IpInfoipInfo(IpInfo)anthor;return(this。ipAddress。equals(ipInfo。ipAddress)amp;amp;this。portipInfo。portamp;amp;this。location。equals(ipInfo。location)amp;amp;this。anonymousType。equals(ipInfo。anonymousType)amp;amp;this。type。equals(ipInfo。type)amp;amp;this。confirmTime。equals(ipInfo。confirmTime))amp;amp;this。getPostSupport。equals(ipInfo。getPostSupport)amp;amp;this。responseSpeed。equals(ipInfo。responseSpeed);}OverridepublicinthashCode(){inthash5;hash89hash(this。ipAddress!null?this。ipAddress。hashCode():0);hash89hashthis。port;hash89hash(this。location!null?this。location。hashCode():0);hash89hash(this。anonymousType!null?this。anonymousType。hashCode():0);hash89hash(this。type!null?this。type。hashCode():0);hash89hash(this。confirmTime!null?this。confirmTime。hashCode():0);hash89hash(this。getPostSupport!null?this。getPostSupport。hashCode():0);hash89hash(this。responseSpeed!null?this。responseSpeed。hashCode():0);returnhash;}OverridepublicStringtoString(){returnipAddressipAddress,portport,localtionlocation,anonymousTypeanonymousType,typetype,confirmTimeconfirmTime,getPostSupportgetPostSupport,responseSpeedresponseSpeed;}privateStringipAddress;privateintport;privateStringlocation;privateStringanonymousType;privateStringtype;privateStringconfirmTime;privateStringgetPostSupport;privateStringresponseSpeed;} 2。Vote。javapackagecom。hust。grid。leesf。entrance;importjava。util。Timer;importjava。util。concurrent。BlockingQueue;importjava。util。concurrent。LinkedBlockingQueue;importcom。hust。grid。leesf。bean。IpInfo;importcom。hust。grid。leesf。thread。IPCollectTask;importcom。hust。grid。leesf。thread。VoteThread;publicclassVote{privateBlockingQueuelt;IpInfogt;ipInfoQueue;privateIPCollectTaskipCollectTask;privateVoteThreadvoteThread;publicVote(){ipInfoQueuenewLinkedBlockingQueuelt;IpInfogt;();ipCollectTasknewIPCollectTask(ipInfoQueue);voteThreadnewVoteThread(ipInfoQueue);}publicvoidvote(){TimertimernewTimer();longdelay0;longperiod10006060;每一个小时采集一次iptimer。scheduleAtFixedRate(ipCollectTask,delay,period);开启投票任务voteThread。start();}publicstaticvoidmain(String〔〕args){VotevotenewVote();vote。vote();}} 3。IPCollectTask。javapackagecom。hust。grid。leesf。thread;importjava。io。IOException;importjava。util。ArrayList;importjava。util。List;importjava。util。TimerTask;importjava。util。concurrent。BlockingQueue;importjava。util。concurrent。LinkedBlockingQueue;importorg。jsoup。Jsoup;importorg。jsoup。nodes。Document;importorg。jsoup。nodes。Element;importorg。jsoup。select。Elements;importcom。hust。grid。leesf。bean。IpInfo;publicclassIPCollectTaskextendsTimerTask{privateBlockingQueuelt;IpInfogt;ipInfoQueue;连接生产者与消费者的阻塞队列privateListlt;IpInfogt;historyIpLists;记录已经获取的ip信息publicIPCollectTask(BlockingQueuelt;IpInfogt;ipInfoQueue){this。ipInfoQueueipInfoQueue;this。historyIpListsnewArrayListlt;IpInfogt;();}获取www。xicidaili。com的ip地址信息publicvoidgetXiCiDaiLiIpLists(){Stringurlhttp:www。xicidaili。com;Stringhostwww。xicidaili。com;DocumentdocgetDocumentByUrl(url,host);解析页面的ip信息parseXiCiDaiLiIpLists(doc);}解析页面的ip信息paramdocpublicvoidparseXiCiDaiLiIpLists(Documentdoc){ElementseleListsdoc。getElementsByTag(tbody);ElementtbodyeleLists。get(0);获取tbodyElementstrListstbody。children();Elementelenull;for(inti0;ilt;trLists。size();i){if((i220)(i221)){去掉不符合条件的项continue;}eletrLists。get(i);ElementschildrenListele。children();StringipAddresschildrenList。get(1)。text();intportInteger。parseInt(childrenList。get(2)。text());StringlocationchildrenList。get(3)。text();StringanonymousTypechildrenList。get(4)。text();StringtypechildrenList。get(5)。text();StringconfirmTimechildrenList。get(6)。text();IpInfoipInfonewIpInfo(ipAddress,port,location,anonymousType,type,confirmTime);putIpInfo(ipInfo);}}将ip信息放入队列和历史记录中paramipInfoprivatevoidputIpInfo(IpInfoipInfo){if(!historyIpLists。contains(ipInfo)){若历史记录中不包含ip信息,则加入队列中加入到阻塞队列中,用作生产者try{ipInfoQueue。put(ipInfo);}catch(InterruptedExceptione){TODOAutogeneratedcatchblocke。printStackTrace();}加入历史记录中historyIpLists。add(ipInfo);}}根据网页Document解析出ip地址信息paramdocprivatevoidparseKuaiDaiLiIpLists(Documentdoc){ElementseleListsdoc。getElementsByTag(tbody);ElementtbodyeleLists。get(0);获取tbodyElementstrListstbody。children();获取十条ip记录for(Elementtr:trLists){遍历trElementstdElementstr。children();tr中的td包含了具体的信息StringipAddresstdElements。get(0)。text();intportInteger。parseInt(tdElements。get(1)。text());StringanonymousTypetdElements。get(2)。text();StringtypetdElements。get(3)。text();StringgetPostSupporttdElements。get(4)。text();StringlocationtdElements。get(5)。text();StringresponseSpeedtdElements。get(6)。text();StringconfirmTimetdElements。get(7)。text();IpInfoipInfonewIpInfo(ipAddress,port,location,anonymousType,type,confirmTime,getPostSupport,responseSpeed);putIpInfo(ipInfo);}}根据提供的url和host来获取页面信息paramurlparamhostreturnprivateDocumentgetDocumentByUrl(Stringurl,Stringhost){Documentdocnull;try{docJsoup。connect(url)。header(UserAgent,Mozilla5。0(WindowsNT6。1;WOW64;rv:43。0)Gecko20100101Firefox43。0)。header(Host,host)。timeout(5000)。get();}catch(IOExceptione){e。printStackTrace();}returndoc;}获取http:www。kuaidaili。comfree的ipprivatevoidgetKuaiDaiLiFreeIpLists(){第一次访问,需解析总共多少页StringbaseUrlhttp:www。kuaidaili。comfreeinha;Stringhostwww。kuaidaili。com;DocumentdocgetDocumentByUrl(baseUrl,host);解析ip信息parseKuaiDaiLiIpLists(doc);ElementlistNavdoc。getElementById(listnav);获取listnav下的li列表ElementsliListslistNav。children()。get(0)。children();获取含有多少页的子元素ElementpageNumberEleliLists。get(liLists。size()2);解析有多少页intpageNumberInteger。parseInt(pageNumberEle。text());拼接成其他页的访问地址for(intindex1;indexlt;pageNumber;index){baseUrlbaseUrlindex;docgetDocumentByUrl(baseUrl,host);parseKuaiDaiLiIpLists(doc);休眠一秒fallSleep(1);}}获取www。kuaidaili。comproxylist的ipprivatevoidgetKuaiDaiLiIpLists(){intstart1;StringbaseUrlhttp:www。kuaidaili。comproxylist;Stringhostwww。kuaidaili。com;while(startlt;10){爬取10页StringurlbaseUrlstart;DocumentdocgetDocumentByUrl(url,host);解析ip信息parseKuaiDaiLiIpLists(doc);start;休眠一秒fallSleep(1);}}进行休眠privatevoidfallSleep(longseconds){try{Thread。sleep(seconds1000);}catch(InterruptedExceptione){e。printStackTrace();}}Overridepublicvoidrun(){getKuaiDaiLiFreeIpLists();System。out。println(IPCollecttaskisrunning);getKuaiDaiLiIpLists();getXiCiDaiLiIpLists();}publicBlockingQueuelt;IpInfogt;getIpInfoQueue(){returnipInfoQueue;}publicstaticvoidmain(String〔〕args){BlockingQueuelt;IpInfogt;queuenewLinkedBlockingQueuelt;IpInfogt;();IPCollectTasktasknewIPCollectTask(queue);ThreadthreadnewThread(task);thread。start();try{Thread。sleep(301000);}catch(InterruptedExceptione){TODOAutogeneratedcatchblocke。printStackTrace();}System。out。println(queuesizeisqueue。size());try{while(!queue。isEmpty()){System。out。println(queue。take());}}catch(InterruptedExceptione){e。printStackTrace();}System。out。println(historyListsizeistask。historyIpLists。size());}} 4。VoteThread。javapackagecom。hust。grid。leesf。thread;importjava。io。IOException;importjava。util。concurrent。BlockingQueue;importorg。apache。http。HttpEntity;importorg。apache。http。HttpHost;importorg。apache。http。HttpResponse;importorg。apache。http。client。ClientProtocolException;importorg。apache。http。client。HttpClient;importorg。apache。http。client。methods。HttpGet;importorg。apache。http。conn。params。ConnRoutePNames;importorg。apache。http。impl。client。DefaultHttpClient;importorg。apache。http。params。HttpConnectionParams;importorg。apache。http。params。HttpParams;importorg。apache。http。util。EntityUtils;importcom。hust。grid。leesf。bean。IpInfo;publicclassVoteThreadextendsThread{privateBlockingQueuelt;IpInfogt;ipInfoQueue;publicVoteThread(BlockingQueuelt;IpInfogt;ipInfoQueue){this。ipInfoQueueipInfoQueue;}Overridepublicvoidrun(){HttpClientclientnewDefaultHttpClient();HttpParamsparamsclient。getParams();HttpConnectionParams。setConnectionTimeout(params,10000);HttpConnectionParams。setSoTimeout(params,15000);HttpResponseresponsenull;HttpGetgetnull;HttpEntityentitynull;HttpHostproxynull;while(true){IpInfoipInfonull;try{ipInfoipInfoQueue。take();}catch(InterruptedExceptione1){TODOAutogeneratedcatchblocke1。printStackTrace();}proxynewHttpHost(ipInfo。getIpAddress(),ipInfo。getPort());client。getParams()。setParameter(ConnRoutePNames。DEFAULTPROXY,proxy);getnewHttpGet(http:www。hnxdf。comvoteiRadiovote。asp?VoTeid215);get。addHeader(Host,www。hnxdf。com);get。addHeader(UserAgent,Mozilla5。0(WindowsNT6。1;WOW64;rv:43。0)Gecko20100101Firefox43。0);try{responseclient。execute(get);entityresponse。getEntity();byte〔〕bytesEntityUtils。toByteArray(entity);对响应内容编码格式进行转化,统一成utf8格式StringtempnewString(bytes,gbk);byte〔〕contentDatatemp。getBytes(utf8);System。out。println(newString(contentData));System。out。println();}catch(ClientProtocolExceptione){e。printStackTrace();}catch(IOExceptione){e。printStackTrace();}}}} 七、系统总结 此系统很简单,想清楚思路之后很快就能够写出代码,系统运行时,由于代理IP站点提供的免费IP质量不是太高,有效的IP地址还是很少,所有效果不是特别理想,此系统功能也很简单,但是各位园友可以在此基础上去发挥自己的想象力,定制属于自己的投票系统。