2015年10月7日 星期三 阴
幼儿园老师天天号召大家投票,要给她老公投票投第一,天天烦死了。昨晚忍不住写了个程序帮她投票,大概原理如下:
-
写脚本抓取网上可用的免费代理: [code]‘http://www.proxylists.net/?HTTP', ‘http://www.scrapeboxproxies.net/', ‘http://uks.pl.ua/script/getproxy.php?last', ‘http://checkerproxy.net/all_proxy', ‘http://ab57.ru/downloads/proxyold.txt', ‘http://www.freeproxy.ru/download/lists/goodproxy.txt', ‘http://www.proxylists.net/http_highanon.txt', ‘http://www.atomintersoft.com/high_anonymity_elite_proxy_list', ‘http://www.atomintersoft.com/transparent_proxy_list', ‘http://www.atomintersoft.com/anonymous_proxy_list', ‘http://www.proxy4free.info/', ‘http://tools.rosinstrument.com/proxy/plab100.xml', ‘http://proxy.ipcn.org/proxylist2.html', ‘http://www.rmccurdy.com/scripts/proxy/good.txt', ‘http://wapland.org/proxy/proxy.txt', ‘http://best-proxy.ru/feed',[/code]
-
把抓取的代理,甄别筛选出真正有用的代理(网上大部分的都是没用的)。
-
投票 伪造UA:在github上找一个比较大的UA列表,每次投票随机投出一次。 USER_AGENT_LIST[random.randint(0,len(USER_AGENT_LIST)-1)] 伪造姓名:每次投票分别在姓的列表和名的列表随机抽一个拼出来。 name = LastName[random.randint(0,len(LastName)-1)] + FirstName[random.randint(0,len(FirstName)-1)] 伪造手机号码: mobile = ‘13%d%d%d’ % (random.randint(1,9),random.randint(1000,9999),random.randint(1000,9999))
-
写了一个用代理投票的函数,具体细节要参考Firebug投票的request头构造 [code]def post_url_data(url,postdata = None, proxy = None, port = None): nFail = 0 while nFail < 1: try: if proxy and port: proxy_handler = urllib2.ProxyHandler({‘http’ : ‘http://%s:%s’ % (proxy,port)}) else: proxy_handler = urllib2.ProxyHandler({}) opener = urllib2.build_opener(proxy_handler) urllib2.install_opener(opener)
if postdata: req = urllib2.Request(url = url,data = postdata) else: req = urllib2.Request(url) req.add_header(‘Accept’, ’text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8’) req.add_header(‘Accept-Language’, ‘zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3’) req.add_header(‘Accept-Encoding’, ‘gzip, deflate’) req.add_header(‘User-Agent’, USER_AGENT_LIST[random.randint(0,len(USER_AGENT_LIST)-1)]) req.add_header(‘Connection’, ‘keep-alive’) req.add_header(‘Cookie’, ‘PHPSESSID=fgv6m7oaosfd1k9g0um1hvtgp3’) req.add_header(‘Host’, ‘×××××××××××.com’) req.add_header(‘Referer’, ‘http://×××××××××××’) req.add_header(‘Content-Length’, ‘62’) req.add_header(‘Content-Type’, ‘application/x-www-form-urlencoded’)
rsp = urllib2.urlopen(req) #print rsp.code return rsp.read() except Exception,e: nFail += 1 #print ‘get url fail:%s count=%d e=%s’ % (url,nFail,e) #print ‘get url fail:%s’ % (url) return None[/code]
- 用可用的代理轮流调用投票程序
...