# !/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib2
import urllib
import cookielib
import json
import httplib
import time
import re
import os
import requests
s=requests.session()
print s.headers
url = "https://www.awfae.com/validcode/generate-validcode.do"
r = s.get(url)
r=r.content
#print s
print type(r)
print r
filename='E:image.jpg'
local = open(filename,'wb')
local.write(r)
local.close()
print "登录二维码已经下载到本地"+"["+filename+"]"
##打开图片
os.system("start %s" % filename);
code = raw_input('输入验证码: ')
print code;
print len(code)
login_url='https://www.awfae.com/business/dispatch_post.do'
data = {'action':'doLogin','userName': '18072722237','followId':'','userPass':'79e8fe923f031f46221a9283d0c9263a','validCode':code}
#data = urllib.urlencode(data)
headers={
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:54.0) Gecko/20100101 Firefox/54.0',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
}
response = s.post(login_url, data=data,headers=headers)
print response
print response.status_code
print response.content
#返回的跳转URL
print response.url
repurl='https://www.awfae.com/web/auth?method=%2Fclient%2Fassetlist&platform=web&_=1508406995591'
r= s.get(repurl,headers=headers)
r = r.content
print r
print type(r)
print type(r)
text = json.loads(r)
print type(text)
print text['data']
print type( text['data'])
print text['data'][0]
print text['data'][0]['exchangeName']