`

自动投票——种种

阅读更多

最近闲余时间做了一些功能——主角本来是php的curl extension的,后来因为投票的网站突然加上了验证码,而我实在不会用php写识别部分,就换到了groovy的httpbuilder上了,一样好用,尤其是开了多线程,效率不错,用jconsole监视下,还可以。

 

下面描述下过程并贴点代码:

 

很多投票时根据IP和投票间隔时间做限制的,所以——

 

1. 弄到一些代理的ip/port/schema——这个推荐在http://www.5uproxy.net找。

  用URL获取html源码正则匹配取得。

 

2. 找到最终投票的URL和表单参数,需要post的,需要一些token或额外字段的,弄好。

 

3. 如果需要验证码的,简单点的推荐去看http://fireinwind.iteye.com/blog/766260,我稍微修改了下,代码如下

 

 

import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.imageio.ImageIO;

public class ImagePreProcess {

	public static int isWhite(int colorInt) {
		Color color = new Color(colorInt);
		if (color.getRed() + color.getGreen() + color.getBlue() > 320) {
			return 1;
		}
		return 0;
	}

	public static int isBlack(int colorInt) {
		Color color = new Color(colorInt);
		if (color.getRed() + color.getGreen() + color.getBlue() <= 100) {
			return 1;
		}
		return 0;
	}

	public static BufferedImage removeBackgroud(InputStream is)
			throws Exception {
		BufferedImage img = ImageIO.read(is);
		int width = img.getWidth();
		int height = img.getHeight();
		for (int x = 0; x < width; ++x) {
			for (int y = 0; y < height; ++y) {
				if (isWhite(img.getRGB(x, y)) == 1) {
					img.setRGB(x, y, Color.WHITE.getRGB());
				} else {
					img.setRGB(x, y, Color.BLACK.getRGB());
				}
			}
		}
		return img;
	}

	public static List<BufferedImage> splitImage(BufferedImage img)
			throws Exception {
		List<BufferedImage> subImgs = new ArrayList<BufferedImage>();
		subImgs.add(img.getSubimage(6, 4, 9, 12));
		subImgs.add(img.getSubimage(19, 4, 9, 12));
		subImgs.add(img.getSubimage(32, 4, 9, 12));
		subImgs.add(img.getSubimage(45, 4, 9, 12));
		return subImgs;
	}

	public static Map<BufferedImage, String> loadTrainData() throws Exception {
		Map<BufferedImage, String> map = new HashMap<BufferedImage, String>();
		File dir = new File("num");
		File[] files = dir.listFiles();
		for (File file : files) {
			map.put(ImageIO.read(file), file.name[0]);
		}
		return map;
	}

	public static String getSingleCharOcr(BufferedImage img,
			Map<BufferedImage, String> map) {
		String result = "";
		int width = img.getWidth();
		int height = img.getHeight();
		int min = width * height;
		for (BufferedImage bi : map.keySet()) {
			int count = 0;
			Label1: for (int x = 0; x < width; ++x) {
				for (int y = 0; y < height; ++y) {
					if (isWhite(img.getRGB(x, y)) != isWhite(bi.getRGB(x, y))) {
						count++;
						if (count >= min)
							break Label1;
					}
				}
			}
			if (count < min) {
				min = count;
				result = map.get(bi);
			}
		}
		return result;
	}

	public static String getAllOcr(InputStream is) {
		try {
			BufferedImage img = removeBackgroud(is);
			List<BufferedImage> listImg = splitImage(img);
			
			Map<BufferedImage, String> map = loadTrainData();
			String result = "";
			for (BufferedImage bi : listImg) {
				result += getSingleCharOcr(bi, map);
			}
			return result;
		}catch (ex) {
		    ex.printStackTrace();
			return ''
		}finally {
		    is.close();
		}
	}

	/** 
	 * @param args 
	 * @throws Exception 
	 */
	public static void main(String[] args) throws Exception {
		String ff = "**.jpeg";
		String text = getAllOcr(new FileInputStream(ff));
		System.out.println(text);
	}
}

 

 其中splitImage方法里,的像素级别的参数,一定在Photoshop或类似软件里看好了;

 而且还要准备元图片(jpg)——就是如果是0-9数字类的,就需要10个数字单独的图以和splitImage后的BufferImage做像素级别的模糊匹配度计算。这样就能稍微解决下简单的图片数字识别了——

 

4. 下面就是Groovy的HttpBuilder做http模拟操作了——至于Groovy的HttpBuilder,看下官方的例子,很容易,你懂的。。。

 

 

@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.5.0-RC2' )
import groovyx.net.http.*
import static groovyx.net.http.ContentType.*
import static groovyx.net.http.Method.*


def postVote(String line){
	if(!line)
		return

	File logOkFile = new File("./log/ok.resp.txt")
	File logErrorFile = new File("./log/error.resp.txt")

	final String domain = '****'
	def http = new HTTPBuilder(domain)

	String[] arr = line.split(':')
	http.setProxy(arr[0], Integer.parseInt(arr[1]), 'http')

	String vc = '' // 验证码
	try {
		http.request( GET ) { req  ->
			req.getParams().setParameter("http.socket.timeout", new Integer(10000))

			uri.path = 'get_verifycode_url.do'

			headers.'User-Agent' = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Mozilla/4.0(Compatible Mozilla/4.0(Compatible-EmbeddedWB 14.59 http://bsalsa.com/ EmbeddedWB- 14.59  from: http://bsalsa.com/ ; Mozilla/4.0(Compatible Mozilla/4.0EmbeddedWB- 14.59  from: http://bsalsa.com/ ; IEShow Toolbar; IEShow stock01ToolBar)'
			response.success = { resp, reader ->
				ByteArrayOutputStream bbos = new ByteArrayOutputStream()
				bbos << reader
				byte[] bb = bbos.toByteArray()
				
				InputStream is = new ByteArrayInputStream(bb)
				vc = ImagePreProcess.getAllOcr(is)
			}
		}

		if(vc){ // 如果取得了验证码则进行投票
			http.request( POST, HTML ) {
				uri.path = 'target_vote.do'
				uri.query = [param1:'val1']

				headers.'User-Agent' = 'Mozilla/5.0 Ubuntu/8.10 Firefox/3.0.4'
				response.success = { resp, reader ->
					logOkFile.append new Date().toString() + ' - ' + reader.text
				}

				response.failure = { resp ->
					logErrorFile.append "Unexpected error: ${resp.statusLine.statusCode} : ${resp.statusLine.reasonPhrase}"
				}
			}
		}
	}catch (ConnectException ex) {
		logErrorFile.append 'Connect failed! ' + line
	}catch (SocketTimeoutException ex) {
		logErrorFile.append 'Connect timeout! ' + line
	}
}

int lineCount = 0
new File("./ip_ll2.txt").eachLine{line -> // 代理ip列表
	lineCount++
	if(lineCount >= 150 && lineCount < 200){ // 控制使用范围,即开启线程数量
		Thread.start('post_thread_' + lineCount){
			Random r = new Random()
			20.times{tt ->
				postVote(line)
				sleep(1000 * r.nextInt(20))
			}	
			
			println 'End thread for ' + lineCount
		}
	}
}
 

 

分享到:
评论

相关推荐

    自动投票工具2014自动投票软件v1.0绿色版

    自动投票工具2014是一款简单易用自动投票软件,该软件能够采用真实独立的IP,并且按照活动网站的要求来正规投票,更加安全、快速,让用户的使用更加放心。而且该软件完全模拟手工操作快速投票,用户只要运行软件即可...

    投票网——数据库详细设计.doc

    投票网——数据库详细设计 本系统需要四个表: 一、用户...userInfo )内用户编号(UID)最大的几个 sql="select top 5 * from userInfo order by UID desc" ----------------------- 投票网——数据库详细设计全文共

    易语言网页自动投票

    易语言网页自动投票源码,网页自动投票

    全自动投票

    本款投票软件和其他自动投票软件的优势是:完全免费,设置简单,无需繁琐的参数,只需截取一段投票信息即可自动投票。 智能高效:全自动投票,投票软件能自动拨号换ip 极速体验:投票速度快,正常情况下一台电脑可达...

    OutdoVote通用自动投票软件

    1、全自动投票,无需人工干预; 2、投票速度快,如果没有IP限制,一般情况下1~2秒一票; 3、不限使用电脑数量,也可在一台电脑上运行多个投票软件(通用投票软件一台电脑只能运行一个); 4、软件运行时,可最小化到...

    自动投票工具V0.01 绿色免费版.rar

    通用免费全自动投票软件,一款强大的投票工具,帮助你获取更多选票,使用方法如下: 投票设置---》对于需要更换IP的投票需要使用这个选项,填入你的ADSL账号,密码即可,如果是内网的话可能无法使用. 模拟投票---...

    易语言源码易语言自动投票源码.rar

    易语言源码易语言自动投票源码.rar 易语言源码易语言自动投票源码.rar 易语言源码易语言自动投票源码.rar 易语言源码易语言自动投票源码.rar 易语言源码易语言自动投票源码.rar 易语言源码易语言自动投票源码....

    超好用自动投票软件 v9.0.zip

    超好用自动投票软件更新说明: 更新优化了部分内核,提高了软件的效率   超好用自动投票软件和其他自动投票软件的优势是:完全免费,设置简单,无需繁琐的参数,只需截取一段投票信息即可自动投票。   智能...

    免费图片投票系统——tpphp

    图片投票PHP V 1.0.1 方便安装、调试

    自动投票小工具源代码

    web 控件操作例程,使用的技术包括: 浏览器视图的使用 网页form及input按钮的读写以及自动提交form 定时器的使用 图形数字识别 ...可以自己修改不同的投票对象为他进行自动投票 最后编译环境是vs2008

    投票网——数据库详细设计(1).doc

    投票网——数据库详细设计 本系统需要四个表: 一、用户信息表(userInfo): ...userInfo )内用户编号(UID)最大的几个 sql="select top 5 * from userInfo order by UID desc" ----------------------- 投票网——

    ASP.NET——ASP.NET利用Cookie处理网上重复投票

    ASP.NET——ASP.NET利用Cookie处理网上重复投票ASP.NET——ASP.NET利用Cookie处理网上重复投票ASP.NET——ASP.NET利用Cookie处理网上重复投票

    在线论坛投票系统——可禁止/防止用户重复投票

    这一个在线投票系统,可以防止用户重复投票,我已经试过了,可以用的!

    C语言课程设计——投票系统开发

    这就要求本程序要能够录入20位候选人的名单,包括起编号和姓名,然后程序可以接受用户的投票,并且自动作出票数统计并输出最后的票数由高到低的排序结果。 二、分析与设计 1.程序的基本功能: (1)查看十佳运动员的...

    518tt投票软件 v20.1.zip

    518tt投票软件和其他自动投票软件的优势是:完全免费,设置简单,无需繁琐的参数,只需截取一段投票信息即可自动投票。 518tt投票软件功能: 智能高效:全自动投票,投票软件能自动拨号换ip 极速体验:投票速度快,...

    全自动投票,无需人工干预

    1.全自动投票,无需人工干预 2.投票速度快,自动循环拨号, 清Cookies,单运行一个投票机即可达每分钟20票以上 3.不限使用电脑数量,非IP限制投票可在一台电脑上运行多个投票机 4.投票机运行时,不影响电脑正常...

    自动投票(c#源码)

    自动投票(c#源码)

    全自动投票软件(自动投票器) V9.9 绿色免费版.zip

    要是GET方式投票的,很简单,把前面GET后面的东西前面加上这个网站的网址组成新的网址输入到请输入投票地址 然后软件上的HTTP请求头设置上的REFER就写上抓到的REFER后面的网址  如果是POST方式投票的 。写的方法...

    电视台自动投票软件(开发)

    电视台自动投票电视台自动投票电视台自动投票电视台自动投票电视台自动投票电视台自动投票电视台自动投票电视台自动投票电视台自动投票

    全自动投票软件 v2.1 绿色版.rar

    全自动投票软件(网络投票软件)免费绿色版,支持GET与POST提交方式,使用简单,绿色无需安装,可自动换IP,跳过cookie 等功能。

Global site tag (gtag.js) - Google Analytics