@
gogobody python , 2.7 依赖 mechanize 。
"""
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,useproxy=0,proxyaddr='http://127.0.0.1:8580'):
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
"""