Example #1
0
        private void btn_getCT_Click(object sender, EventArgs e)
        {
            List <LinkInfo> list_linkinfo = new List <LinkInfo>();

            if (wb.ReadyState != WebBrowserReadyState.Complete)
            {
                return;
            }

            LinkInfo loc_lf;
            //HtmlElementCollection hec = wb.Document.Links;
            HTMLAnchorElementClass link;

            for (int i = 0; i < wb.Document.Links.Count; i++)
            {
                link = (HTMLAnchorElementClass)wb.Document.Links[i].DomElement;

                if (list_linkinfo.Exists(p => p.href == link.href))
                {
                    continue;
                }
                loc_lf = new LinkInfo();

                loc_lf.tag       = link.tagName;
                loc_lf.innerText = link.innerText;
                loc_lf.href      = link.href;
                loc_lf.visited   = 0;
                list_linkinfo.Add(loc_lf);
            }
            var    ejahi   = wb.Document.Window.Frames;
            string outhtml = wb.Document.Body.OuterHtml;
            var    windows = wb.Document.Body.GetElementsByTagName("IFRAME");
            //var windows = wb.Document.Window;

            //HtmlWindow real = (mshtml.HTMLIFrameClass)(windows[2].DomElement);
            //wb.Url = new Uri("http://api.so.lianmeng.360.cn/searchthrow/api/ads/throw?ls=s4e6a6cc694&w=635&h=150&inject=1&pos=0&rurl=http%3A%2F%2Fwww.aikeya020.com%2F&pn=0&prt=1462502056889&tit=%E5%87%BA%E5%9B%BD%E7%A7%BB%E6%B0%91%E7%BD%91%20-%20%E5%90%84%E5%9B%BD%E5%87%BA%E5%9B%BD%E7%A7%BB%E6%B0%91%E8%B5%84%E8%AE%AF&pt=1462502056887&cw=1255&dpr=1&jv=1437124819535&inlay=0&link=45&rank=25&imagelink=4&searchlink=15&imagetext=0%2C0");
            //wb.Url = new Uri("http://www.baidu.com");
            var khkn = wb.Document.Body.All;
            var jh   = wb.Document.Links;

            foreach (HtmlElement item in jh)
            {
                if (item.OuterHtml != null && item.OuterHtml.Contains("http://e.tf.360.cn/search/eclk?"))
                {
                    Console.WriteLine(item.OuterHtml);
                }
            }
            List <LinkInfo> loc_adas = list_linkinfo.AsEnumerable().Where(q => q.href.StartsWith("https://e.tf.360.cn/search/eclk?")).ToList();

            HtmlDocument objDoc = wb.Document;

            foreach (HtmlElement element in objDoc.Body.All)
            {
                if (element.TagName.ToLower().Equals("iframe"))
                {
                    foreach (HtmlElement child in element.All)
                    {
                        if (child.OuterText.Contains("http://e.tf.360.cn/search/eclk?"))
                        {
                            Console.WriteLine(child.OuterText);
                        }

                        string text = child.GetAttribute("type").ToLower();
                        if (text == "radio" || text == "checkbox")
                        {
                            child.SetAttribute("checked", "checked");
                        }
                    }
                }
            }


            if (loc_adas.Count > 0)
            {
                wb.DocumentCompleted -= new WebBrowserDocumentCompletedEventHandler(Wb_DocumentCompleted);
            }
        }