Dear Telerik Team,
I want to import data from different websites with HTML Agility Pack. Then I want to export data to my SQL database. I have little problem because every cell return my " " . I use method from this website:
http://www.telerik.com/forums/access-cell-values-in-radgrid-selected-index-event
So I think that problem is in import data.
I attach 2 sample code."Row" file return me correct data, but return me the same problem. I think that "Cell" sample code should return me correct data but in every rows display the same information.
Cell Code:
WebClient webClient = new WebClient();
StreamReader page = new StreamReader(WebRequest.Create("http://nolimits.art.pl/grafik/wyswietl.php?typ=2").GetResponse().GetResponseStream(), Encoding.UTF8);
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.Load(page);
HtmlNode node = doc.DocumentNode.SelectSingleNode("//table");
string context = node.InnerHtml;
DataTable NLTable = new DataTable();
//NLTable.Columns.Add(" ");//CheckBox
NLTable.Columns.Add("Dzien tygodnia");
NLTable.Columns.Add("Godziny zajec");
NLTable.Columns.Add("Nazwa zajec");
NLTable.Columns.Add("Poziom");
NLTable.Columns.Add("Instruktor");
NLTable.Columns.Add("Wolne miejsce dla");
foreach (HtmlNode row in node.SelectNodes("tr"))
{
if (row.InnerText != "" && row.InnerHtml.IndexOf("<th>") < 0 && row.InnerHtml.IndexOf("background-color") < 0)
{
TableRow tRow = new TableRow();
foreach (HtmlNode cell in row.SelectNodes("td"))
{
TableCell tCell = new TableCell();
tCell.Text = cell.InnerText;
tRow.Cells.Add(tCell);
}
NLTable.Rows.Add(tRow);
}
}
rgSynchronize.DataSource = NLTable;
rgSynchronize.DataBind();
}
Cell Sample code:
WebClient webClient = new WebClient();//string page = webClient.DownloadString("http://nolimits.art.pl/grafik/wyswietl.php?typ=1");
StreamReader page = new StreamReader(WebRequest.Create("http://nolimits.art.pl/grafik/wyswietl.php?typ=2").GetResponse().GetResponseStream(), Encoding.UTF8);
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.Load(page);
HtmlNode node = doc.DocumentNode.SelectSingleNode("//table");
string context = node.InnerHtml;
DataTable NLTable = new DataTable();
NLTable.Columns.Add(" ");//CheckBox
NLTable.Columns.Add("Dzien tygodnia");
NLTable.Columns.Add("Godziny zajec");
NLTable.Columns.Add("Nazwa zajec");
NLTable.Columns.Add("Poziom");
NLTable.Columns.Add("Instruktor");
//NLTable.Columns.Add("Nr sali");
NLTable.Columns.Add("Wolne miejsce dla");
foreach (HtmlNode row in node.SelectNodes("tr"))
{
if (row.InnerText != "" && row.InnerHtml.IndexOf("<th>") < 0 && row.InnerHtml.IndexOf("background-color") < 0)
NLTable.Rows.Add(row.InnerHtml);
}
rgSynchronize.DataSource = NLTable;