python 获取美元实际汇率

 

 

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

  

上一篇:Python网络编程相关的库与爬虫基础


下一篇:python爬虫——requests