This project has moved and is read-only. For the latest updates, please go here.

Search for specific row

Topics: Developer Forum
Jan 25, 2013 at 6:40 PM
Edited Jan 25, 2013 at 6:43 PM

I've been parsing out a page and I've reach a point where I'm stuck. I'm looking at a two column table and I just want the specific row containing the word "Earnings date" to be returned. Right now, I get all the rows. I'm attach the out put below. Is there a way to then convert it to a datable? thanks for your help in advance.

var infoNode = document.DocumentNode.SelectSingleNode("//table[@class='snapshot-table2']");

var rows = infoNode.SelectNodes("//tr[@class='table-dark-row']");
var data = infoNode.SelectNodes("//td[@body='snapshot-td2-cp']");

 foreach (HtmlNode row in rows) {
                if (row.InnerText.Contains("Earnings")) {
                    earningsdate = row.InnerHtml.ToString();
                    var result = row.SelectNodes("//td");

<td width="7%" class="snapshot-td2-cp" align="left" title="cssbody=[tooltip_short_bdy] cssheader=[tooltip_short_hdr] body=[Long Term Debt to Equity (mrq)] offsetx=[10] offsety=[20] delay=[300]">LT Debt/Eq</td><td width="8%" class="snapshot-td2" align="left"><b>0.31</b></td>
<td width="7%" class="snapshot-td2-cp" align="left" title="cssbody=[tooltip_short_bdy] cssheader=[tooltip_short_hdr] body=[Earnings date

BMO = Before Market Open AMC = After Market Close] offsetx=[10] offsety=[20] delay=[300]"
>Earnings</td><td width="8%" class="snapshot-td2" align="left"><b>Feb 18</b></td>
Jan 25, 2013 at 9:44 PM

Think I have it working, below is what I ended up using:


        private static DataTable ParseTable(HtmlNode table)
            var result = new DataTable();

            var rows = table.Descendants("tr");

            result.Columns.Add(new DataColumn("Title", typeof(string)));
            result.Columns.Add(new DataColumn("Value", typeof(string)));

            foreach (var row in rows.Skip(1))
                var data = new List();
                int x = 1;

                foreach (var column in row.Descendants("td"))
                    if (x == 2)
                        x = 0;

            return result;