博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
IHTMLDocument2类的使用
阅读量:4617 次
发布时间:2019-06-09

本文共 1439 字,大约阅读时间需要 4 分钟。

 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 == "")
                    {
                        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

你可能感兴趣的文章
Windows平台flex+gcc词法分析实验工具包
查看>>
3.Python基础 序列sequence
查看>>
Chapter 4 Syntax Analysis
查看>>
vi/vim使用
查看>>
讨论Spring整合Mybatis时一级缓存失效得问题
查看>>
Maven私服配置Setting和Pom文件
查看>>
Linux搭建Nexus3.X构建maven私服
查看>>
Notepad++使用NppFTP插件编辑linux上的文件
查看>>
NPOI 操作Excel
查看>>
MySql【Error笔记】
查看>>
vue入门
查看>>
JS线程Web worker
查看>>
Flex的动画效果与变换!(三)(完)
查看>>
mysql常见错误码
查看>>
Openresty 与 Tengine
查看>>
使用XV-11激光雷达做hector_slam
查看>>
布局技巧4:使用ViewStub
查看>>
ddt Ui 案例2
查看>>
拿下主机后内网的信息收集
查看>>
LeetCode 876. Middle of the Linked List
查看>>