前言
相信大家平时肯定会收到朋友发来的链接,打开一看,哦,需要投票。投完票后弹出一个页面(恭喜您,您已经投票成功),再次点击的时候发现,啊哈,您的IP(***.***.***.***)已经投过票了,不能重复投票。这时候,我们可能会想,能不能突破ip地址的限制进行刷票呢?有了这样的想法,那就去做吧,下面我将介绍我这个简单的刷票系统,仅供有需求的园友们参考。
1.系统设计
系统主要实现的是突破IP限制进行刷票,其中,由IP采集模块负责从互联网上爬取代理IP,放入阻塞队列,该任务会定期执行。之后由投票模块从阻塞队列中获取IP,并进行设置,然后进行投票。系统流程图如下:
2.系统技术
系统使用HttpClient + JSoup + 多线程来完成刷票,HttpClient用于进行投票,JSoup用于解析页面,多线程技术用于分离任务,使得分工更加明确。使用到了生产者消费者模式,该模式直接使用BlockingQueue来实现。
3、系统介绍
系统主要分为三个模块:
①.IP采集模块
②.投票模块
③.IP信息模块
其中,IP采集模块主要是从互联网爬取IP代理信息,并将该信息放入阻塞队列,这样就可以伪造IP,进行多次投票。
其中,投票模块从IP采集模块放入阻塞队列取出IP信息,并设置代理,找到投票入口地址,然后进行投票操作。
其中,IP信息模块主要是对爬取的IP信息进行了封装,方便其他模块进行操作。
3.1.IP采集模块
IP采集模块流程图如下
几点说明:
1.系统使用的代理IP站点URL为http://www.kuaidaili.com/,www.xicidaili.com。
2.提取IP信息为提取单条IP信息,并判断历史IP表是否已经存在,若存在,表示之前已经加入过此IP信息,则直接丢弃,反之,则加入队列并加入历史IP表。
3.此任务会定期开启,如一个小时爬取一次代理IP。
3.2.投票模块
投票模块流程图如下
几点说明:
1.投票网站http://www.hnxdf.com/vote/,我们选取的第一位进行投票,分析出投票的入口为http://www.hnxdf.com/vote/iRadio_vote.asp?VoTeid=215。
2.根据IP采集模块放入队列的IP信息进行设置,然后进行投票。
3.3.IP信息模块
此模块主要对从网站爬取的IP信息进行了封装,方便其他模块进行操作。
4、系统代码框架
系统的整个代码框架如下
其中,bean包的IpInfo封装了爬取的IP信息。
其中,entrance包的Vote为系统的入口。
其中,thread包的IPCollectTask为爬取代理IP任务,VoteThread为进行投票线程。
5.系统代码
1.IpInfo.java
package com.hust.grid.leesf.bean;
public class IpInfo {
public IpInfo(String ipAddress, int port, String location,
String anonymousType, String type, String confirmTime) {
this(ipAddress, port, location, anonymousType, type, confirmTime, null,
null);
}
public IpInfo(String ipAddress, int port, String location,
String anonymousType, String type, String confirmTime,
String getPostSupport, String responseSpeed) {
this.ipAddress = ipAddress;
this.port = port;
this.location = location;
this.anonymousType = anonymousType;
this.type = type;
this.confirmTime = confirmTime;
this.getPostSupport = getPostSupport;
this.responseSpeed = responseSpeed;
}
public String getIpAddress() {
return ipAddress;
}
public void setIpAddress(String ipAddress) {
this.ipAddress = ipAddress;
}
public int getPort() {
return port;
}
public void setPort(int port) {
this.port = port;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public String getAnonymousType() {
return anonymousType;
}
public void setAnonymousType(String anonymousType) {
this.anonymousType = anonymousType;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getConfirmTime() {
return confirmTime;
}
public void setConfirmTime(String confirmTime) {
this.confirmTime = confirmTime;
}
public String getGetPostSupport() {
return getPostSupport;
}
public void setGetPostSupport(String getPostSupport) {
this.getPostSupport = getPostSupport;
}
public String getResponseSpeed() {
return responseSpeed;
}
public void setResponseSpeed(String responseSpeed) {
this.responseSpeed = responseSpeed;
}
@Override
public boolean equals(Object anthor) {
if (this == anthor) {
return true;
}
if (anthor == null || getClass() != anthor.getClass()) {
return false;
}
IpInfo ipInfo = (IpInfo) anthor;
return (this.ipAddress.equals(ipInfo.ipAddress)
&& this.port == ipInfo.port
&& this.location.equals(ipInfo.location)
&& this.anonymousType.equals(ipInfo.anonymousType)
&& this.type.equals(ipInfo.type) && this.confirmTime
.equals(ipInfo.confirmTime))
&& this.getPostSupport.equals(ipInfo.getPostSupport)
&& this.responseSpeed.equals(ipInfo.responseSpeed);
}
@Override
public int hashCode() {
int hash = 5;
hash = 89 * hash
+ (this.ipAddress != null ? this.ipAddress.hashCode() : 0);
hash = 89 * hash + this.port;
hash = 89 * hash
+ (this.location != null ? this.location.hashCode() : 0);
hash = 89
* hash
+ (this.anonymousType != null ? this.anonymousType.hashCode()
: 0);
hash = 89 * hash + (this.type != null ? this.type.hashCode() : 0);
hash = 89 * hash
+ (this.confirmTime != null ? this.confirmTime.hashCode() : 0);
hash = 89
* hash
+ (this.getPostSupport != null ? this.getPostSupport.hashCode()
: 0);
hash = 89
* hash
+ (this.responseSpeed != null ? this.responseSpeed.hashCode()
: 0);
return hash;
}
@Override
public String toString() {
return "ipAddress = " + ipAddress + ", port = " + port + ", localtion = "
+ location + ", anonymousType = " + anonymousType + ", type = "
+ type + ", confirmTime = " + confirmTime + ", getPostSupport = "
+ getPostSupport + ", responseSpeed = " + responseSpeed;
}
private String ipAddress;
private int port;
private String location;
private String anonymousType;
private String type;
private String confirmTime;
private String getPostSupport;
private String responseSpeed;
}