Example #1
0
        private void GetListThreads ()
        {
            listThreads = new List<Model.Thread> ();

            HtmlNodeCollection listThreadNode = doc.DocumentNode
                .SelectSingleNode ( "//tbody[@id='threadbits_forum_" + boxId + "']" ).SelectNodes ( "./tr" );
            HtmlNodeCollection nodesTd, nodeDiv;
            HtmlNode node_second_td, node_id, node_replies, node_view, node_lastpost;

            foreach ( HtmlNode nodeSingleThread in listThreadNode )
            {
                //get all <td> (total 5)
                nodesTd = nodeSingleThread.SelectNodes ( "./td" );
                if ( nodesTd[1].Attributes["class"].Value == "alt2" )
                    nodesTd.RemoveAt ( 1 );
                if ( nodesTd.Count == 5 )
                {
                    Model.Thread thread = new Model.Thread ();

                    //1st node contain id
                    node_id = nodesTd[0];
                    thread.id = node_id.Attributes["id"].Value.Remove ( 0 , 20 );

                    //2nd node contain title and creating user and first unread
                    node_second_td = nodesTd[1];
                    nodeDiv = node_second_td.SelectNodes ( "./div" );
                    HtmlNodeCollection nodesInFirstDiv = nodeDiv[0].SelectNodes ( "./a" );
                    foreach ( HtmlNode a in nodesInFirstDiv )
                    {
                        thread.title += a.InnerText + " ";
                    }
                    thread.title = HtmlEntity.DeEntitize ( thread.title );
                    thread.creatingUser = HtmlEntity.DeEntitize ( nodeDiv[1].InnerText.Trim () );

                    //3rd node contain last post info
                    node_lastpost = nodesTd[2];
                    thread.lastPost = HtmlEntity.DeEntitize ( node_lastpost.InnerText.Trim () );
                    string[] s = thread.lastPost.Split ();
                    thread.lastPost = string.Join ( " " , s );

                    //4th contain replies
                    node_replies = nodesTd[3];
                    thread.replies = node_replies.InnerText;

                    //5th contain view
                    node_view = nodesTd[4];
                    thread.views = node_view.InnerText;

                    //get new post link
                    HtmlNode newPostNode = node_second_td.SelectSingleNode ( ".//a[@id='thread_gotonew_" + thread.id + "']" );
                    if ( newPostNode != null )
                    {
                        thread.newPost = HtmlEntity.DeEntitize ( newPostNode.Attributes["href"].Value );
                        thread.title = "[NEW] " + thread.title;
                    }
                    else
                    {
                        thread.newPost = "";
                    }

                    //last page
                    HtmlNode span = node_second_td.SelectSingleNode ( ".//span[@class='smallfont']" );
                    if ( span != null )
                    {
                        HtmlNodeCollection pages = span.SelectNodes ( ".//a" );
                        thread.lastPage = HtmlEntity.DeEntitize ( ( ( HtmlNode ) pages.Last () ).Attributes["href"].Value );
                        thread.lastPage = thread.lastPage.Split ( new char[] { '&' } )[1];
                    }
                    else
                    {
                        thread.lastPage = "";
                    }
                    listThreads.Add ( thread );
                }
            }
        }
Example #2
0
        private void GetListThreads()
        {
            listThreads = new List <Model.Thread> ();

            HtmlNodeCollection listThreadNode = doc.DocumentNode
                                                .SelectSingleNode("//tbody[@id='threadbits_forum_" + boxId + "']").SelectNodes("./tr");
            HtmlNodeCollection nodesTd, nodeDiv;
            HtmlNode           node_second_td, node_id, node_replies, node_view, node_lastpost;

            foreach (HtmlNode nodeSingleThread in listThreadNode)
            {
                //get all <td> (total 5)
                nodesTd = nodeSingleThread.SelectNodes("./td");
                if (nodesTd[1].Attributes["class"].Value == "alt2")
                {
                    nodesTd.RemoveAt(1);
                }
                if (nodesTd.Count == 5)
                {
                    Model.Thread thread = new Model.Thread();

                    //1st node contain id
                    node_id   = nodesTd[0];
                    thread.id = node_id.Attributes["id"].Value.Remove(0, 20);

                    //2nd node contain title and creating user and first unread
                    node_second_td = nodesTd[1];
                    nodeDiv        = node_second_td.SelectNodes("./div");
                    HtmlNodeCollection nodesInFirstDiv = nodeDiv[0].SelectNodes("./a");
                    foreach (HtmlNode a in nodesInFirstDiv)
                    {
                        thread.title += a.InnerText + " ";
                    }
                    thread.title        = HtmlEntity.DeEntitize(thread.title);
                    thread.creatingUser = HtmlEntity.DeEntitize(nodeDiv[1].InnerText.Trim());

                    //3rd node contain last post info
                    node_lastpost   = nodesTd[2];
                    thread.lastPost = HtmlEntity.DeEntitize(node_lastpost.InnerText.Trim());
                    string[] s = thread.lastPost.Split();
                    thread.lastPost = string.Join(" ", s);

                    //4th contain replies
                    node_replies   = nodesTd[3];
                    thread.replies = node_replies.InnerText;

                    //5th contain view
                    node_view    = nodesTd[4];
                    thread.views = node_view.InnerText;

                    //get new post link
                    HtmlNode newPostNode = node_second_td.SelectSingleNode(".//a[@id='thread_gotonew_" + thread.id + "']");
                    if (newPostNode != null)
                    {
                        thread.newPost = HtmlEntity.DeEntitize(newPostNode.Attributes["href"].Value);
                        thread.title   = "[NEW] " + thread.title;
                    }
                    else
                    {
                        thread.newPost = "";
                    }

                    //last page
                    HtmlNode span = node_second_td.SelectSingleNode(".//span[@class='smallfont']");
                    if (span != null)
                    {
                        HtmlNodeCollection pages = span.SelectNodes(".//a");
                        thread.lastPage = HtmlEntity.DeEntitize((( HtmlNode )pages.Last()).Attributes["href"].Value);
                        thread.lastPage = thread.lastPage.Split(new char[] { '&' })[1];
                    }
                    else
                    {
                        thread.lastPage = "";
                    }
                    listThreads.Add(thread);
                }
            }
        }