由于前几日入了Google 5太子 刷的是招行的信用卡中的美元账户在结算的时候就需要看下哪天的比较低看还款合适,那么在招行的网站中找了下页面很容易就查找到了汇率的走势图,分析了下网页其是一个xml的文件。解析很简单用到了xml.etree 中的 ElementTree.代码如下

import urllib2
from xml.etree import ElementTree as ET

url = ‘http://fx.cmbchina.com/CmbFxWebService/RealrateService.aspx?_=1383963963135&func=History&startdate=2009-01-01&enddate=2013-11-09&nbr=%u7F8E%u5143&type=days

page = urllib2.urlopen(url)
tree=ET.parse(page)
root = tree.getroot()

for child in root:
exchange = child.find(‘ZRtcBid’).text
date = child.find(‘ZRatDat’).text
print ‘%s @ %s’ % (exchange, date)

输出部分数据如下: 601.61 @ 2013-10-27 602.42 @ 2013-10-28 602.86 @ 2013-10-29 603.16 @ 2013-10-30 603.31 @ 2013-10-31 603.14 @ 2013-11-01 603.14 @ 2013-11-03 603.14 @ 2013-11-03 603.85 @ 2013-11-04 603.50 @ 2013-11-05 603.16 @ 2013-11-06 603.01 @ 2013-11-07 602.35 @ 2013-11-08 看样子是一直在走低,所以拖到最后一天再还款啦~~ 打完收工