用python写代码抓取外汇汇率和提示USDCNY不超过6.7的最优价格买入?
def get_money():
import re
import json
import urllib.request
url = "http://webforex.hermes.hexun.com/forex/quotelist?code=FOREXUSDCNY&column=Code,Price"
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0'}
req = urllib.request.Request(url=url, headers=headers)
f=urllib.request.urlopen(req).read()
html = f
s = re.findall("{.*}",str(html))[0]
sjson = json.loads(s)
USDCNY = float(sjson["Data"][0][0][1]/10000)
return USDCNY
a=get_money()
if a<=6.7:
print('当前可以'+str(a)+'的价格买入')