汇率计算器问题(谷歌) [英] Problem with exchange rate calculator (google)

查看:122
本文介绍了汇率计算器问题(谷歌)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我想将兑换货币换成另一种货币,以下是代码



Hello all,

I want to convert exchange rage from one currency to another, Following is the code

string txt;
                        string url = "http://www.google.com/finance/converter?a=1&from=USD&to=INR";

                        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                        WebResponse response = request.GetResponse();
                        using (Stream responseStream = response.GetResponseStream())
                        {
                            StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
                            txt = reader.ReadToEnd();
                        }







txt变量的输出为完整形式HTML页面。以下是html输出的一部分




the out put of "txt" variable is in the form of full html page. following is the part of html output

<div id=currency_converter_result>1 USD = <span class=bld>62.9100 INR</span>
<input type=submit value="Convert">
</div>







之前我试过以下代码但没有成功...






Previously I have tried following code but not success ...

string response = web.DownloadString(url);

           Regex regex = new Regex("rhs: \\\"(\\d*.\\d*)");
           Match match = regex.Match(response);

           rate = System.Convert.ToDecimal(match.Groups[1].Value);







以前我的代码工作正常,但谷歌API更改后我的代码没有用....



我正在搜索解决方案

1.我可以将我的货币序列化为json格式

2.我可以使用web.config文件中的google api,yahoo api等任何API,我的代码适用于所有人。





请帮助我并建议我提供完美的解决方案。

我正在使用C#编写我的应用程序。在MVC 4中。





提前致谢



问候,

Manoj




Previously my code was working, but after the change of google API my code not worked ....

I am searching the solution as
1. I can serialize my currency Rate in to json format
2. I can use any API like google api , yahoo api , etc from the web.config file and my code will work for all.


Please help me and suggest me with perfect solution.
I am writing my app. in MVC 4 , with C#.


Thanks in advance

With Regards,
Manoj

推荐答案

当你依赖网站抓取时(就像你一样)你总是面临失败的风险,因为网络网站可以随意更改(通常是)。



相反,请查看一些API解决方案(其中许多是免费的)并使用服务而不是基于解决方案。



Google:货币转换器服务api [ ^ ]
When you rely on site scraping (as you do) you are always at risk of failure, because web sites can be changed at will (and often are).

Instead, look at some of the API solutions out there (many of which are free) and use a service based solution instead.

Google: currency converter service api[^]


我想在这里你想转换货币,我建议只使用免费的网络服务以标准格式兑换货币。



请访问: http://www.webservicex.net/ws/WSDetails.aspx?WSID=10&CATID=2 [ ^ ]
I think here you want to convert the currency , I suggest just use free web service it can convert Money in an Standard Form.

please Visit : http://www.webservicex.net/ws/WSDetails.aspx?WSID=10&CATID=2[^]


这篇关于汇率计算器问题(谷歌)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆