本文介绍如何使用Python获取美元人民币实时汇率
# -*- coding: utf-8 -*-# @Author: 比特量化# @Date: -08-26import reimport jsonimport urllib.requesturl = "http://webforex./forex/quotelist?code=FOREXUSDCNY&column=Code,Price"req = urllib.request.Request(url)f = urllib.request.urlopen(req)html = f.read().decode("utf-8")print(html)s = re.findall("{.*}",str(html))[0]sjson = json.loads(s)USDCNY = sjson["Data"][0][0][1]/10000print(USDCNY)
返回如下
({"Data":[[["USDCNY",70807]]]});7.0807