i have html page where there are many elements one of them is a table . How can i get the values in the table and append them to datatable i use html agility asp.net c#
this table is in scrpit code and have (\)with each item
<script type="text/javascript">
<!--
bklkl.abc.writeWidget({'cons':'bobj.crv.newpage'; style sheet properties with alot of character})
<\table cellspacing="0" cellpadding="3" rules="cols" id="page1">
<\tr>
<\th scope="col">h1</th>
<\th scope="col">h2</th>
<\th scope="col">h3 </th>
<\th scope="col"> h4</th>
<\th scope="col"> h5</th>
<\tr>
<\tr >
<\td><input type="button" value="edit" /></td>
<\td>value 1</td>
<\td>value 2 </td>
<\td>value 3</td>
<\td>value 4</td>
</tr>
<\table>
</script>
i cant get the table because of the css and java code ??
i even try
string text = Regex.Replace(infodata.InnerText, @"</?\w+((\s+\w+(\s*=\s*(?:"".*?""|'.*?'|[^'"">\s]+))?)+\s*|\s*)/?>", string.Empty).Replace(@"\r\n", "").Replace(@"\", "").Replace(@"\r\", "");
but i get still css code that i cant reach or read the table
What I have tried:
This is my trial
<pre lang="C#">HtmlNodeCollection tables = pag1.Html.SelectNodes("//table[@id='data']");
DataTable tb = new DataTable();
HtmlNodeCollection rows = tables[0].SelectNodes("tr");
// create the columns
HtmlNodeCollection cols = rows[0].SelectNodes("th");
if (cols != null)
{
for (int j = 0; j <= cols.Count - 1; j++)
{
tb.Columns.Add(cols[j].InnerText);
}
}
// Now fill the table
for (int i = 0; i <= rows.Count - 1; i++)
{
var newRow = tb.NewRow();
HtmlNodeCollection cols = rows[i].SelectNodes("td");
if (cols != null)
{
for (int j = 0; j <= cols.Count - 1; j++)
{
newRow[j] = cols[j].InnerText;
}
}
// add the row to table
tb.Rows.Add(newRow);
}