平价网站建设,朝扬网络,个人怎么做微信公众号和微网站,wordpress增加微语python爬取人民币汇率中间价#xff0c;从最权威的网站中国外汇交易中心。首先找到相关网页#xff0c;解析链接#xff0c;这中间需要经验和耐心#xff0c;在此不多说。以人民币兑美元的汇率为例(CNY/USD)#xff0c;脚本详情如下#xff1a;windows#xff1a;# -*- …python爬取人民币汇率中间价从最权威的网站中国外汇交易中心。首先找到相关网页解析链接这中间需要经验和耐心在此不多说。以人民币兑美元的汇率为例(CNY/USD)脚本详情如下windows# -*- coding: utf-8 -*-import timeimport requestsimport jsont time.time()# 这里必须是ms级别的时间戳timestamp (int(round(t*1000)))url http://www.chinamoney.com.cn/r/cms/www/chinamoney/data/fx/ccpr.json?tstr(timestamp)s requests.Session()r s.post(url,data{})sjson json.loads(r.text)#print sjsonfor k in sjson[records]:if k[vrtEName] USD/CNY:print k[price]Linux# -*- coding: utf-8 -*-import timeimport urllibimport urllib2import jsont time.time()# timestamp must be mstimestamp (int(round(t*1000)))url http://www.chinamoney.com.cn/r/cms/www/chinamoney/data/fx/ccpr.json?tstr(timestamp)data urllib.urlencode({})request urllib2.Request(url,data)response urllib2.urlopen(request)result response.read()rjson json.loads(result)for r in rjson[records]:if r[vrtEName] USD/CNY:return r[price]发现在linux环境下用request返回的是HTML结构。而不是data的json格式所以在linux用urllib和urllib2