Skip to content

Instantly share code, notes, and snippets.

@sophie2805
Created June 26, 2015 11:57
Show Gist options
  • Save sophie2805/54a3ff729074011f91a1 to your computer and use it in GitHub Desktop.
Save sophie2805/54a3ff729074011f91a1 to your computer and use it in GitHub Desktop.
auto login discuz bbs and reply
#-*- coding:utf-8 -*-
__author__ = 'Sophie2805'
import urllib
import urllib2
import time
import re
import cookielib
jar = cookielib.CookieJar()
handler = urllib2.HTTPCookieProcessor(jar)
opener = urllib2.build_opener(handler)
params ={
'user.account':'***',
'user.pwd':'***'
}
headers = {'User-Agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Firefox/38.0'}
url = 'http://bbs.wacai.com/'#/forum-16056-1.html
req = urllib2.Request(url, headers=headers)
bbs_page = urllib2.urlopen(req,urllib.urlencode(params))
bbs_html= bbs_page.read()
cookie = bbs_page.info()['set-cookie']
print cookie
pattern_2 = 'name="formhash" value="' + '.+"'
p_2 = re.compile(pattern_2)
result_2 = p_2.findall(bbs_html)
'''
title = '签到有礼'+(time.strftime("%m.%d")+'0').strip('0')+'每天签到得铜钱,每人限回一次'
pattern_1 = '<.+>'+title
p_1 = re.compile(pattern_1)
pattern_2 = 'name="formhash" value="' + '.+"'
p_2 = re.compile(pattern_2)
result_1 = p_1.findall(bbs_html)
result_2 = p_2.findall(bbs_html)
'''
formhash = result_2[0][result_2[0].find('value="')+7:result_2[0].find('value="')+15]
link_today = 'http://bbs.wacai.com/forum.php?mod=post&action=reply&fid=16056&tid=644887&extra=&replysubmit=yes&infloat=yes&handlekey=fastpost&inajax=1'#'http://bbs.wacai.com/'+ result[0][result[0].find('a href="')+8:result[0].find(' onclick=')-1]
reply={
'formhash':formhash,
'message':'貌似是赠送到余额里面的'
}
h ={
'User-Agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Firefox/38.0',
'Referer':'http://bbs.wacai.com/thread-645253-1-1.html',
'Host':'bbs.wacai.com',
'Cookie': cookie
}
req_thread = urllib2.Request(link_today,headers=h)
page = urllib2.urlopen(req_thread,urllib.urlencode(reply))
print '~~~~~~'
print page.info()['set-cookie']
print '~~~~~'
print page.read()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment