获取中国银行网页中外汇率
来源:互联网 发布:gta捏脸数据女生 编辑:程序博客网 时间:2024/04/28 13:36
using System;using System.Collections.Generic;using System.Text;//============================using System.Net;using System.IO;namespace BOSS.网关程序.日常工作{ public class synchronousRate { public Dictionary<string, double> getRate() { //字典---------------------------------------------------------------------------- Dictionary<string, double> huobi = new Dictionary<string, double>(); //-------------------------------------------------------------------------------- string strHtml = GetWebContent("http://www.boc.cn/sourcedb/whpj/enindex.html").Trim(); HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument(); doc.LoadHtml(strHtml); doc.OptionOutputAsXml = true; HtmlAgilityPack.HtmlNode node = doc.DocumentNode.SelectSingleNode(".//table[tr/th=\"Currency Name\"]"); //if (node == null) //{ // Show("没有找到有th为Currency Name列的table", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Information); // return; //} HtmlAgilityPack.HtmlNodeCollection trNodeList = node.SelectNodes("tr[td]"); foreach (HtmlAgilityPack.HtmlNode trNode in trNodeList) { //DataRow dr = dt.NewRow(); //dt.Rows.Add(dr); //for (int j = 0; j < 7; j++) //{ // HtmlAgilityPack.HtmlNodeCollection tdNodeList = trNode.SelectNodes("td"); // dr[j] = tdNodeList[j].InnerText.Replace(" ", " "); //} HtmlAgilityPack.HtmlNodeCollection tdNodeList1 = trNode.SelectNodes("td"); switch (tdNodeList1[0].InnerText.Replace(" ", " ")) { case "AUD": case "EUR": case "GBP": case "USD": huobi.Add(tdNodeList1[0].InnerText.Replace(" ", " "), double.Parse(tdNodeList1[4].InnerText) / 100); break; } } return huobi; } private string GetWebContent(string strUrl) { string str = ""; try { WebClient wc = new WebClient(); wc.Credentials = CredentialCache.DefaultCredentials; Encoding enc = Encoding.GetEncoding("UTF-8");// 如果是乱码就改成 UTF-8 / GB2312 //方法一: //Byte[] buffer = wc.DownloadData(strUrl);// 从资源下载数据并返回字节数组 //str = enc.GetString(buffer);// 输出字符串(HTML代码) //方法二: Stream res = wc.OpenRead(strUrl);//以流的形式打开URL //Stream res = new FileStream(@"E:\ExchangeRate\enindex.html", FileMode.Open, FileAccess.Read); StreamReader sr = new StreamReader(res, enc);//以指定的编码方式读取数据流 str = sr.ReadToEnd();//输出(HTML代码) res.Close(); wc.Dispose(); } catch (Exception ex) { } return str; } }}
0 0
- 获取中国银行网页中外汇率
- 抓取中国银行汇率函数
- 抓取中国银行汇率函数 2008年12月29日
- 获取在线汇率
- 获取当前汇率
- JAVA 获取实时汇率
- 获取人民币外汇汇率
- 使用Jsoup抓取网页内容,获取美元兑人民币外汇汇率
- 自动获取美元最新汇率
- java获取汇率 美元-人民币
- 汇率
- ABAP 获取当天汇率的方法
- SAP ABAP:获取汇率的完整实现之一
- SAP ABAP:获取汇率的完整实现之一
- SAP ABAP:获取汇率的完整实现之一
- 什么是汇率
- 有效汇率
- 计算汇率
- 数据库存储过程
- struts2的上传
- 【自考】排序算法-插入、交换、选择、归并排序
- MYSQL数据丢失讨论
- volatile
- 获取中国银行网页中外汇率
- A5-1和DES两个加密算法的学习
- 金正恩已经一个月“消逝”于大众视界
- Nhibernate分页测试续(附源码)
- mongodb配置及应用实例
- struts2下载
- OpenSSH <=6.6 SFTP misconfiguration exploit for 64bit Linux
- 局部敏感哈希算法的实现
- grunt