Skip to content

Instantly share code, notes, and snippets.

@sophie2805
Created June 26, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sophie2805/c2e77d61eed2bfdd7f3a to your computer and use it in GitHub Desktop.
Save sophie2805/c2e77d61eed2bfdd7f3a to your computer and use it in GitHub Desktop.
using python requests auto login and reply
#-*- coding:utf-8 -*-
__author__ = 'Sophie2805'
import re
import time
import requests
agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Firefox/38.0'
s = requests.Session()
s.headers.update({'User-Agent':agent})
login_url ='https://www.wacai.com/user/user!login.action?cmd=null'
login_post_data ={
'user.account':'***',
'user.pwd':'***'
}
r = s.post(login_url,login_post_data)
t = s.get('http://bbs.wacai.com/portal.php')
pattern_2 = 'name="formhash" value="' + '.+"'
p_2 = re.compile(pattern_2)
result_2 = p_2.findall(t.content)
formhash = result_2[0][result_2[0].find('value="')+7:result_2[0].find('value="')+15]
print formhash
reply_data={
'formhash':formhash,
'message':'都不敢买了',
'posttime':str(time.time())[0:10]
}
t_url = 'http://bbs.wacai.com/forum.php?mod=post&action=reply&fid=16066&tid=646084&extra=&replysubmit=yes&infloat=yes&handlekey=fastpost&inajax=1'#'http://bbs.wacai.com/forum.php?mod=post&action=reply&fid=16056&tid=644887&extra=&replysubmit=yes&infloat=yes&handlekey=fastpost&inajax=1'
x = s.post(t_url,reply_data)
print x.content
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment