Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
All day long i was trying to get familiar with HTML Agility Pack.
I am just learning C#.
Website is www.tikr.ru
I need main quote - which is 1519.95 for today.
I even got XPath expression for it, which is //*[@id="csPrice"] using FireBug for Firefox.
I can't understand what's wrong with this code.


C#
static void Main(string[] args)
{
    var webGet = new HtmlWeb();
    var document = webGet.Load("http://www.tikr.ru");
    var prices = from lnks in document.DocumentNode.Descendants()
          where lnks.Name == "//*[@id='csPrice']"
          select new { Price = lnks.Attributes["csPrice"].Value};

    foreach(var item in prices)
    {
        string message = "The Price is: " + item.Price.ToString();
        Console.WriteLine(message);
        Console.ReadLine();
    }
}
Posted
Updated 20-Sep-11 7:57am
v2

This will do your work
C#
void GetQuote()
{
            WebClient wb = new WebClient();
            string htmldoc= wb.DownloadString("http://www.tikr.ru/");
            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
            doc.LoadHtml(htmldoc);
            HtmlAgilityPack.HtmlNode node = doc.DocumentNode.SelectSingleNode("//span[@id=\"csPrice\"]");
            string quote = node.InnerText;
}


Here the 'quote' directly displays the today's quote i.e 1519.95 .

:)
 
Share this answer
 
v2
Thank you very much. This is very useful reply!!! I think it will be helpful for other users also.
 
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