forked from zhanghe06/python
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathweb.py
More file actions
93 lines (72 loc) · 2.48 KB
/
web.py
File metadata and controls
93 lines (72 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# encoding: utf-8
__author__ = 'zhanghe'
import os
import tornado.httpserver
import tornado.web
import tornado.ioloop
import tornado.options
import requests
import json
# from handlers import *
from tornado.options import define, options
define("port", default=8000, help="run on the given port", type=int)
s = requests.session()
# 登录页的url
url = 'https://trade.1234567.com.cn/do.aspx/CheckedCS'
# 配置User-Agent
header = {
'Content-Type': 'application/json; charset=UTF-8', # 因为是ajax请求,格式为json,这个必须指定
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36'
}
class IndexHandler(tornado.web.RequestHandler):
def data_received(self, chunk):
pass
def get(self):
self.render('index.html')
def post(self):
self.render('index.html')
class LoginHandler(tornado.web.RequestHandler):
def data_received(self, chunk):
pass
def post(self):
payload = self.get_argument("payload", '')
print payload
response = s.post(url, data=payload, headers=header)
content = response.text
print content
return self.render('login.html', payload=payload, content=content)
class QQHandler(tornado.web.RequestHandler):
def data_received(self, chunk):
pass
def get(self):
self.render('web_qq/index.html')
class QQPasswordHandler(tornado.web.RequestHandler):
def data_received(self, chunk):
pass
def get(self):
self.render('web_qq/password.html')
handlers = [
(r'/', IndexHandler),
(r'/login', LoginHandler),
(r'/qq', QQHandler),
(r'/qq/password', QQPasswordHandler),
# (r'/member', memberHandler),
# (r'/chat/(\d+)', chatHandler),
# (r'/register', registerHandler),
# (r'/logout', logoutHandler),
# (r'/post', postHandler),
# (r'/user/(\w+)', userHandler),
# (r'/blog/(\d+)', blogHandler),
# (r'/comment', commentHandler),
]
settings = {
'static_path': os.path.join(os.path.dirname(__file__), 'static'),
'template_path': os.path.join(os.path.dirname(__file__), 'template'),
}
if __name__ == '__main__':
tornado.options.parse_command_line()
app = tornado.web.Application(handlers, **settings)
# http_server = tornado.httpserver.HTTPServer(app)
# http_server.listen(options.port)
app.listen(options.port) # 貌似这一句可以替代上面两句,待研究
tornado.ioloop.IOLoop.instance().start()