views:

100

answers:

2
http://www.dsebd.org/latest_PE.php

The above url contain several information .From this url i just want to get bellow information.How to?

Price Earning Ratio : at a glance
on Aug 2, 2010 at 11:28:00

I want to know how to get url information into a variable or some storage container in C#.Specific i need above information ,i don't need rest of information. I use the bellow syntax:

WebClient objWebClient = new WebClient();

aRequestHTML = objWebClient.DownloadData("http://www.dsebd.org/latest_PE.php");//http://www.dsebd.org/latest_PE_all2_08.php
UTF8Encoding utf8 = new UTF8Encoding();
myString = utf8.GetString(aRequestHTML);
HtmlDocument htmlDoc = new HtmlDocument();
htmlDoc.LoadHtml(myString);

After that what to do?i don't guess any thing.Plz show some syntax

  foreach (HtmlNode node in doc.DocumentNode.SelectNodes(@"//td"))//td[text()="Price Earning Ratio : at a glance"
            {
                if (node.InnerHtml.Contains("Price Earning Ratio"))
                {
                    //I get the td value

                }
                //[text()=Price Earning Ratio : at a glance
                // do stuff with node   //@"//td[text()=Price Earning Ratio : at a glance"
            }

After add the above syntax i get the bellow out put

<br>
      <font color="#FFFFFF" size="3" face="Arial"><b>Price Earning Ratio : at 
      a glance <b> </b></b></font><br>
    <font color="#FFFFFF" size="2" face="Arial"><b> on Aug 2, 2010  at 17:04:00<b></b></b></font>
    <br>

From this i just want to get the Date part .HOw to ?With out this date i don't need any thing.Each day this date will change,It's dynamical date,so i can not inline this date.From above out put how i get the date .

A: 

If you want to download content from above URL you can use WebClient (standard c# class for making http requests) to make the http call and then Html Agility Pack to parse the html and extract the data.

PanJanek
I am new in Html Agility Pack ,I don't know appropriate use of this pack.After see the above code will you plz help me to solve this problem.
shamim
+4  A: 

Take a look at the HTML Agility Pack - it is a HTML parser that lets you pass in a URL which will parse so you can query it using XPath.

HtmlWeb hw = new HtmlWeb();
HtmlDocument doc = hw.Load("http://www.dsebd.org/latest_PE.php");

At this point doc can be queries and looked at:

foreach(HtmlNode node in doc.DocumentNode.SelectNodes("XPATH for interesting nodes"))
{
  // do stuff with node
}
Oded
+1, HTML Agility Pack is very good, I've used it in several projects
Regent
I use this pack but i can not solve this issue,after see the above code will you plz tell What to ?thanks in advance
shamim
@shamim - look at the examples on the site. You need to use xpath to get the nodes you are interested in.
Oded
you given site show how to get data from a[@href,from hyperlink.I told i am new in this pack will you plz show me some syntax.
shamim
@shamim - make an effort then. I will not do all your work for you. As a programmer I always try to learn, not simply use things without understanding them.
Oded