這個主要公司做外貿的每天都需要更新匯率,本來以前有一個服務可以調用,但是那個連接用不了 所以就寫了一個這樣的東西 套取網頁顯示信息
class ExchangeRate
{
private const string _BASEURL = "網頁地址";
public const string CURRENCYCODE = "貨幣類型以|隔開";//貨幣類型
public Hashtable GetValues()
{
Hashtable htReturn = new Hashtable();
string url = _BASEURL; //+ HttpUtility.UrlEncode(tmSet.ToString("yyyy/MM/dd", DateTimeFormatInfo.InvariantInfo));
WebClient wc = new WebClient();
string sHtml = wc.DownloadString(url);
string sXml = string.Empty;
int iValueCnt = CURRENCYCODE.Split(new char[] { | }, 10, StringSplitOptions.RemoveEmptyEntries).Length;
string[] sTBody = sHtml.Split(new string[] { "<tbody>", "</tbody>" }, StringSplitOptions.RemoveEmptyEntries);
foreach (string ss in sTBody)
{
if (ss.Contains("Currency Name"))
{
string[] sbrs = ss.Split(new string[] { "</tr>" }, StringSplitOptions.RemoveEmptyEntries);
foreach (string sbr in sbrs)
{
string scur = string.Empty;
double dRate =