Skip to content

Instantly share code, notes, and snippets.

@liuzhe0223
Created September 24, 2013 12:21
Show Gist options
  • Save liuzhe0223/6683950 to your computer and use it in GitHub Desktop.
Save liuzhe0223/6683950 to your computer and use it in GitHub Desktop.
自动登录 Discuz! 3.x 发帖
#coding:utf-8
import time
import requests
from pyquery import PyQuery as pq
if __name__ == "__main__":
host = "http://www.ytbbs.com/"
loggin_url = ''.join([host, 'member.php'])
loggin_params = {
'mod': 'logging',
'action': 'login',
'loginsubmit': 'yes',
'infloat': 'yes',
'lssubmit': 'yes',
}
loggin_data = {
'username': "***",
'password': "***"
}
headers = {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Encoding': 'gzip,deflate,sdch',
'Accept-Language': 'zh-CN,zh;q=0.8,en-US;q=0.6,en;q=0.4',
'Connection': 'keep-alive',
'Content-Type': 'application/x-www-form-urlencoded',
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36',
}
# r = requests.get("http://www.ytbbs.com")
# cookies = r.cookies
r = requests.post(loggin_url, data=loggin_data, params=loggin_params)
cookies = r.cookies
reply_url = ''.join([host, 'forum.php'])
reply_parmas = {
'mod': 'post',
'action': 'reply',
'fid': '18',
'tid': '5638387',
'extra': 'page=1',
'replysubmit': 'yes',
'infloat': 'yes',
'handlekey': 'fastpost',
'inajax': '1'
}
r = requests.get('http://www.ytbbs.com//plugin.php?id=dsu_paulsign:sign', cookies = cookies)
inputs = pq(r.content)('input')
print len(inputs)
for i in inputs:
try:
if i.attrib['name'] == 'formhash':
formhash = i.attrib['value']
print formhash
if i.attrib['name'] == 'posttime':
posttime = i.attrib['value']
print posttime
except KeyError:
pass
reply_data = {
'message': '11111111111111111111111'.encode('gbk'),
'formhash': formhash,
'posttime': int(time.time()),
'usesig': '',
'subject': '',
}
print reply_data
r = requests.post(reply_url, data=reply_data, params=reply_parmas,
cookies=cookies, headers=headers
)
print r.url
print r.content.decode('gbk').encode('utf-8')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment