Q:

how do i get all the value of a table from a website

string Url = "http://www.dsebd.org/latest_share_price_scroll_l.php";
HtmlWeb web = new HtmlWeb();

HtmlDocument doc = web.Load(Url);
string a = doc.DocumentNode.SelectNodes("//iframe*[@src=latest_share_price_all\"]//html/body/div/table/tbody")[0].InnerText;

i have tried, but null value found in string a.           

A:

Ok this one confused me for a while but I've got it now. Instead of pulling the whole page from http://www.dsebd.org/latest_share_price_scroll_l.php, you can get just the table data from http://www.dsebd.org/latest_share_price_all.php.
There was some strange behaviour with trying to select child elements of the #document node under the iframe element. Someone with more xpath experience might be able to explain this.
Now you can get all the table row nodes by using the following xpath:
string url = "http://www.dsebd.org/latest_share_price_all.php";

HtmlDocument doc = new HtmlWeb().Load(url);
HtmlNode docNode = doc.DocumentNode;

var nodes = docNode.SelectNodes("//body/div/table/tr");

That will give you all the table row nodes. Then you need to go through each node you just got and get the values you want.
Just for example if you wanted to get the trading code, high, and volume you would do the following:
//Remove the first node because it is the header row at the top of the table
nodes.RemoveAt(0);
foreach(HtmlNode rowNode in nodes)
{
    HtmlNode tradingCodeNode = rowNode.SelectSingleNode("td[2]/a");
    string tradingCode = tradingCodeNode.InnerText;

    HtmlNode highNode = rowNode.SelectSingleNode("td[4]");
    string highValue = highNode.InnerText;

    HtmlNode volumeNode = rowNode.SelectSingleNode("td[11]");
    string volumeValue = volumeNode.InnerText;

    //Do whatever you want with the values here
    //Put them in a class or add them to a list
}

XPath uses 1-based indices so when you are referring to a particular cell in a table row by number the first element is at index 1, instead of using index 0 as in a C# array.

