Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 54 lines (42 sloc) 1.339 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
#coding:utf-8
import urllib2
import gevent
from gevent import monkey, queue
monkey.patch_all()

proxy_file = 'proxy.txt'

refer = "http://www.xingfudaiyanren.com/Html/Main.asp?SortID=27&SortPath=0,27"
url = "http://www.xingfudaiyanren.com/Html/PhotoVote.asp?id=36&name=王易慧"

def vote(proxy, url, refer):
    enable_proxy = True
    proxy_handler = urllib2.ProxyHandler({"http" : 'http://%s' % proxy})
    null_proxy_handler = urllib2.ProxyHandler({})
     
    if enable_proxy:
        opener = urllib2.build_opener(proxy_handler)
    else:
        opener = urllib2.build_opener(null_proxy_handler)

    urllib2.install_opener(opener)

    req = urllib2.Request(url)
    req.add_header("User-Agent", 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.18) Gecko/20110614 Firefox/3.6.18')
    req.add_header( "Referer", refer)
    res = urllib2.urlopen( req )
    html = res.read()
    res.close()
    #return html
    print proxy, html

def worker(n):
    while True:
        proxy = q.get()
        try:
            vote(proxy, url, refer)
        except:
            pass
        finally:
            q.task_done()

q = queue.JoinableQueue()
num_worker_threads = 40

proxys = open(proxy_file).readlines()
for p in proxys:
    q.put(p.strip())

for i in range(num_worker_threads):
    gevent.spawn(worker, i)

q.join()
Something went wrong with that request. Please try again.