C# 获取当前网页HTML

2021/12/27 20:08:02

本文主要是介绍C# 获取当前网页HTML,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

//引用COM组件
//Microsoft HTML Object Library
//Microsoft Internet Controls

        SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindowsClass();
        string filename;
        foreach (SHDocVw.InternetExplorer ie in shellWindows)
        {
            filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
            if (filename.Equals("iexplore"))
            {
                SetText(string.Format("Web Site  : {0}", ie.LocationURL));
                mshtml.IHTMLDocument2 htmlDoc = ie.Document as mshtml.IHTMLDocument2;
                SetText(string.Format("  Document Snippet: {0}",
                ((htmlDoc != null) ? htmlDoc.body.outerHTML
                : "***Failed***")));
                SetText(string.Format("{0}{0}", Environment.NewLine));
            }
        }


这篇关于C# 获取当前网页HTML的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程