Click here to Skip to main content
15,886,734 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all,

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

C#
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();
                        }



the out put of "txt" variable is in the form of full html page. following is the part of html output
HTML
<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 ...

C#
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);



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
Posted

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[^]
 
Share this answer
 
Comments
Manoj Kumar Choubey 29-Jan-14 0:41am    
Please suggest me any open source service based API ?
OriginalGriff 29-Jan-14 3:57am    
Did you follow the link to Google? The first hit after the adverts is open source...
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[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900