HtmlAgilityPack problem DataSource

2 posts, 0 answers
  1. Jakub
    Jakub avatar
    2 posts
    Member since:
    Jul 2014

    Posted 07 Sep 2015 Link to this post

    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 "&nbsp" . 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;
  2. Angel Petrov
    Admin
    Angel Petrov avatar
    1082 posts

    Posted 10 Sep 2015 Link to this post

    Hello,

    The problem may be caused by the way the grid is bound. From the code I see that simple data-binding is used(calling .DataBind()). Please modify the grid code so that advanced data-binding is used and test the page again. If this does not prove helpful please share with us the entire page contents(markup and code-behind) so we could further research the matter.

    Regards,
    Angel Petrov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top