0

I've never done web crawling or web-scraping. But now I need to read and download specific data from a forex url and store into database for further data evaluation by developing a automated robot developed in C#. I'm reading the website using the following code:

public static string GetPage(string url)
    {
        try
        {
            HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(url);

            HttpWebResponse resp = (HttpWebResponse)wr.GetResponse();

            Stream s = resp.GetResponseStream();
            StreamReader tr = new StreamReader(s, Encoding.ASCII);
            string html = tr.ReadToEnd();
            tr.Close();
            s.Close();
            

            return html;
        }
        catch (Exception ex)
        {
            throw new ApplicationException("Error downloading web page " + url.ToString(), ex);
        }
    }

But the above code is giving me the whole HTML code for the page where as I need to get the EURO to GBP, USD and CHF conversion rate reading but nothing else. Please refer to the below image for the details:

Screenshot

Now please advice me how do I read those specific data? Is there any proper way to do that or do I need to find it from the HTML extract? Thanks.

barsan
  • 2,431
  • 16
  • 45
  • 62

2 Answers2

0

You can parse html document by using HtmlAgilityPack, simply download it from nuget. Here is a good tutorial about how to implement it.

  • Thanks for the answer but I need to achieve this in C# not in asp.net is this possible to do in C#.net? – barsan Apr 04 '17 at 07:25
  • HtmlAgilityPack not related to asp.net, you can use it in any place of your c# code. – Vova Klimov Apr 04 '17 at 09:50
  • [Here](http://stackoverflow.com/questions/10558149/html-agility-pack-load-and-scrape-webpage) you can find more about how to parse specific page – Vova Klimov Apr 04 '17 at 09:54
  • Yes, I've read it and also started working with it. Thanks for the nice suggestion. – barsan Apr 04 '17 at 09:55
0

With Selenium (which offers an C# API) you can read those values. Check out the API and you will find appropriate functions.

gartenkralle
  • 646
  • 1
  • 11
  • 21