Tuesday, April 23, 2013

Create Webbrowser Runtime And Get Page All Links


private void GetPageLinks(DataTable tbl, string mUrl)
        {
            string strlinks = "" ;
            string LastRowLink = "" ;

            WebBrowser mWB = new WebBrowser();
            mWB.ScriptErrorsSuppressed = true;
            WebClient wc = new WebClient();
            mWB.DocumentText = wc.DownloadString(mUrl);
            do
            {
                Application.DoEvents();
            } while (mWB.ReadyState != WebBrowserReadyState .Complete);

            foreach (HtmlElement item in mWB.Document.Links)
            {
                strlinks = item.GetAttribute( "href");
                    if (Convert .ToInt32(tbl.Compute("Count(link)", "Link='" + strlinks + "'")) == 0)
                    {
                        tbl.Rows.Add(strlinks, "Page", "Pending" );
                        LastRowLink = strlinks;
                    }
            }
            ///// For Getting page url
            if (LastRowLink.Trim() != "" )
            {
                GetPageLinks(tbl, LastRowLink);
                LastRowLink = "";
            }
            /////
        }

No comments:

Post a Comment