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 '--------------------'
print text['data'][0]['exchangeName']
print type(text['data'][0]['exchangeName'])
print len(text['data'][0]['exchangeName'])
print text['data'][0]['exchangeName'].encode('utf-8')
print type(text['data'][0]['exchangeName'].encode('utf-8'))
print len(text['data'][0]['exchangeName'].encode('utf-8'))
在PyCharm返回的是unicode把,unicode转换成utf-8
<type 'str'>
<type 'str'>
<type 'dict'>
[{u'disableBuyAmount': 0, u'totalAvailableBalance': 8.0, u'wzeFrozenBalance': 0.0, u'canRechargeAmount': 0, u'exchangeCode': u'10000001', u'clientSn': 1662, u'frozenWithdraw': 0.0, u'currentInvestBalance': 0, u'todayCashLimit': True, u'availableBalance': 6.1, u'exchangeName': u'u6e29u91d1u6240', u'wzeAvailableBalance': 1.9, u'totalInvestBalance': 0.0, u'frozenPay': 0.0}, {u'disableBuyAmount': 0, u'totalAvailableBalance': 0.0, u'wzeFrozenBalance': 0.0, u'canRechargeAmount': 0, u'exchangeCode': u'10000002', u'clientSn': 1662, u'frozenWithdraw': 0.0, u'currentInvestBalance': 0, u'todayCashLimit': True, u'availableBalance': 0.0, u'exchangeName': u'u9547u91d1u6240', u'wzeAvailableBalance': 0.0, u'totalInvestBalance': 0.0, u'frozenPay': 0.0}]
<type 'list'>
{u'disableBuyAmount': 0, u'totalAvailableBalance': 8.0, u'wzeFrozenBalance': 0.0, u'canRechargeAmount': 0, u'exchangeCode': u'10000001', u'clientSn': 1662, u'frozenWithdraw': 0.0, u'currentInvestBalance': 0, u'todayCashLimit': True, u'availableBalance': 6.1, u'exchangeName': u'u6e29u91d1u6240', u'wzeAvailableBalance': 1.9, u'totalInvestBalance': 0.0, u'frozenPay': 0.0}
--------------------
温金所
<type 'unicode'>
3
温金所
<type 'str'>
9
在cmd运行:
{u'disableBuyAmount': 0, u'totalAvailableBalance': 8.0, u'wzeFrozenBalance': 0.0
, u'canRechargeAmount': 0, u'exchangeCode': u'10000001', u'clientSn': 1662, u'fr
ozenWithdraw': 0.0, u'currentInvestBalance': 0, u'todayCashLimit': True, u'avail
ableBalance': 6.1, u'exchangeName': u'u6e29u91d1u6240', u'wzeAvailableBalance
': 1.9, u'totalInvestBalance': 0.0, u'frozenPay': 0.0}
--------------------
温金所
<type 'unicode'>
3
娓╅噾鎵€
<type 'str'>
9
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 '--------------------'
print text['data'][0]['exchangeName']
print type(text['data'][0]['exchangeName'])
print len(text['data'][0]['exchangeName'])
print text['data'][0]['exchangeName'].encode('gbk')
print type(text['data'][0]['exchangeName'].encode('gbk'))
print len(text['data'][0]['exchangeName'].encode('gbk'))
unicode 转成gbk:
{u'disableBuyAmount': 0, u'totalAvailableBalance': 8.0, u'wzeFrozenBalance': 0.0
, u'canRechargeAmount': 0, u'exchangeCode': u'10000001', u'clientSn': 1662, u'fr
ozenWithdraw': 0.0, u'currentInvestBalance': 0, u'todayCashLimit': True, u'avail
ableBalance': 6.1, u'exchangeName': u'u6e29u91d1u6240', u'wzeAvailableBalance
': 1.9, u'totalInvestBalance': 0.0, u'frozenPay': 0.0}
--------------------
温金所
<type 'unicode'>
3
温金所
<type 'str'>
6