Created
February 11, 2013 16:16
-
-
Save Wizmann/4755463 to your computer and use it in GitHub Desktop.
与SimSimi交互的程序,Hack网页接口,不稳定
This file contains hidden or 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
# coding=utf-8 | |
import sys | |
import requests | |
reload(sys) | |
sys.setdefaultencoding('utf-8') | |
INIT_URL = 'http://www.simsimi.com/talk.htm?lc=ch' | |
TALK_URL = 'http://www.simsimi.com/func/req?msg={0}&lc=ch' | |
HEADERS = {'Accept': 'application/json, text/javascript, */*; q=0.01', | |
'Accept-Charset': 'UTF-8,*;q=0.5', | |
'Accept-Encoding': 'gzip,deflate,sdch', | |
'Accept-Language': 'zh-CN,zh;q=0.8', | |
'Connection': 'keep-alive', | |
'Content-Type': 'application/json; charset=utf-8', | |
'Host': 'www.simsimi.com', | |
'Referer': 'http://www.simsimi.com/talk.htm?lc=ch', | |
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.69 Safari/537.17', | |
'X-Requested-With': 'XMLHttpRequest'} | |
def init(): | |
r = requests.get(INIT_URL, headers=HEADERS) | |
return r.cookies | |
def get_response(talk, cookies): | |
url = TALK_URL.format(talk) | |
cookies['sagree'] = 'true' | |
try: | |
r = requests.get(url, cookies=cookies, headers=HEADERS) | |
return r.json()['response'] | |
except: | |
return u'呵呵' | |
if __name__ == '__main__': | |
cookies = init() | |
while True: | |
s = raw_input('>>> ') | |
print '<<<', get_response(s, cookies) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
except: return '呵呵'
ROFL