Last active
May 18, 2016 08:17
-
-
Save bearqq/05ef0b5c009cb7edc8ca7bcd2405a535 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def make_br(): | |
br = mechanize.Browser(history=NoHistory()) | |
#cj = cookielib.LWPCookieJar() | |
#br.set_cookiejar(cj) | |
br.set_handle_equiv(True) | |
br.set_handle_gzip(True) | |
br.set_handle_redirect(True) | |
br.set_handle_referer(True) | |
br.set_handle_robots(False) | |
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1) | |
br.set_debug_http(False) | |
br.addheaders = [('User-agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0')] | |
#br.set_proxies({"http":"username:password@proxy.com:8888"}) | |
return br | |
class v2ex(object): | |
def __init__(self,v2expara): | |
self.name='v2ex' | |
self.br=make_br() | |
self.v2expara=v2expara #('name','pass') | |
def sign(self): | |
br=self.br | |
br.open('https://www.v2ex.com/signin') | |
#for f in br.forms(): | |
br.select_form(nr=1) | |
for i in br.form.__dict__['controls']: | |
#print i.name,i.type | |
if i.type=='text': | |
br.form[i.name]=self.v2expara[0] | |
elif i.type=='password': | |
br.form[i.name]=self.v2expara[1] | |
br.submit() | |
br.open('https://www.v2ex.com/mission/daily') | |
if u'每日登录奖励已领取' in br.response().read(): | |
return 1 | |
else: | |
br.open(re.search(r'/mission/daily/redeem\?once=\d+', br.response().read()).group()) | |
if u'请重新点击一次以领取每日登录' in response: | |
return 0 | |
elif br.response().read(): | |
return 1 | |
return 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment