IHTMLDocument2类的使用

 class Program
    {
        static void Main(string[] args)
        {
            SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();
            string filename;
            foreach (SHDocVw.InternetExplorer ie in shellWindows)
            {
                filename = "iexplore";// Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
                if (filename.Equals("iexplore"))
                {
                    Console.WriteLine("Web Site   : {0}", ie.LocationURL);
                    mshtml.IHTMLDocument2 htmlDoc = ie.Document as mshtml.IHTMLDocument2;
                    Console.WriteLine("   Document Snippet: {0}", ((htmlDoc != null) ? htmlDoc.body.outerHTML.Substring(0, 40) : "***Failed***"));
                    if (ie.LocationURL == "http://s.taobao.com/search?q=%D2%C2%B7%FE&initiative_id=tbindexz_20130105&commend=all&source=suggest&ssid=s5-e-p1&suggest=0_3&newpre=null&bcoffset=1&s=40#J_FilterTabBar")
                    {
                        SearchTextInGoogle(htmlDoc, "衣服");
                    }
                    Console.WriteLine("{0}{0}", Environment.NewLine);
                }
            }
            Console.WriteLine("完成");
            Console.ReadLine();
        }
        public static void SearchTextInGoogle(mshtml.IHTMLDocument2 ieDoc, string searchText)
        {
            mshtml.HTMLInputElement input;
           
            //set the text to be searched   
            //foreach (mshtml.IHTMLElement ieElement in ieDoc.all)
            //{
            //    //if its tag is input and name is q(question)   
            //    if (ieElement.tagName.ToUpper() == "INPUT")
            //    {
            //        input = ((mshtml.HTMLInputElement)ieElement);
            //        if (input.name == "wd")
            //        {
            //            input.value = searchText;
            //            //break;
            //        }
            //    }
            //}

            //click the submit button to search   
            foreach (mshtml.IHTMLElement ieElement in ieDoc.all)
            {
                //if its tag is input   
                if (ieElement.tagName.ToUpper() == "A")
                {
                   
                    if (ieElement.className == "page-next")
                    {
                        ieElement.click();
                       
                    }
                }
              
            }
        }
    }

转载于:https://www.cnblogs.com/wlzhang/p/3405860.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值