-1

I am making program which will show the text from the table.The structure is like that. there are two tables but I want to get text from the 2nd table. enter image description here

my table data looks like below:

enter image description here

I want to show the first 3 columns of each row of the 2nd table. For this I tried like this.

HtmlWeb web = new HtmlWeb();

HtmlAgilityPack.HtmlDocument doc = web.Load("http://www.banglaeye.com/baby-names/index.php");
HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes("//div[@class='col_box']/table[2]/tr/td");

try
{
    foreach (HtmlNode n in nodes)
    {
        if (k != 0)
        {
            link = n.InnerHtml;
            my_link.Add(link);
            MessageBox.Show(link);               
        }
        k++;
    }
}
catch (NullReferenceException)
{
    MessageBox.Show("No link found");
}

I have found that this URL does a http post method. But Html Agility pack doesn't provide any Http post method. so how can achieve my goal??

ImonBayazid
  • 1,066
  • 3
  • 16
  • 41

1 Answers1

1

The table whose contents you want to grab isn't populated until the user of the browser clicks the "Search" button. If someone were to navigate to that URL normally, they wouldn't see any entries in the table until the button is pressed. That is why HTMLAgilityPack only sees the first row. The button, when clicked, performs an HTTP POST:

letter=All&gender_id=0&origin_id=0&submit=search

Your program must perform this request then load the results into an HtmlDocument using doc.LoadHtml() rather than doc.Load().

Here are some other Stack Overflow questions you can refer to in order to complete those two tasks:

Community
  • 1
  • 1
Hypershadsy
  • 398
  • 4
  • 13
  • i tried this but it got the exception and shows the "No link found" @hypershadsy – ImonBayazid Feb 09 '14 at 07:52
  • 1
    I was wrong about tbody. It seems that Chrome Dev Tools implicitly displays even if it's not in the actual page. I've edited the answer completely. – Hypershadsy Feb 09 '14 at 08:25
  • But Html agility pack doesn't provide the facility of HTTP post . @Hypershadsy – ImonBayazid Mar 07 '14 at 17:17
  • @DarkenShooter HTML agility pack is for reading html, not POSTing HTTP. you can't use HTML agility pack for the POSTing, but the response can be loaded into HTML agility pack if you wish. – Hypershadsy Mar 12 '14 at 23:39