首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何用C#获取IE8/9 active tab html源码

如何用C#获取IE8/9 active tab html源码
EN

Stack Overflow用户
提问于 2010-10-30 22:16:02
回答 1查看 1.9K关注 0票数 1

我正试图在Visual Studio的C#中创建一个程序,该程序将获取Internet Explorer8/(首选) 9中当前打开(或选择,或全部)选项卡的html源代码。我厌倦了通过浏览器复制->查看源代码,alt+a,alt+c,程序-> alt+v有人知道如何解决它吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-10-30 22:24:28

这个问题没有简单的解决方案,我想也许你应该继续复制和粘贴。总之,这就是我在网上找到的:(http://www.experts-exchange.com/Microsoft/Development/Q_23767759.html)

代码语言:javascript
复制
{   // used spy++ to get the names of these guys
            // get the handle to the IE toolbar
            childHandle = FindWindowEx(IEwindowHandle, IntPtr.Zero, "WorkerW", IntPtr.Zero);
            if (childHandle != IntPtr.Zero)
            {
                //get the handle to the address bar on IE
                childHandle = FindWindowEx(childHandle, IntPtr.Zero, "ReBarWindow32", IntPtr.Zero);
                if (childHandle != IntPtr.Zero)
                {
                    // get a handle to comboBoxEx32
                    childHandle = FindWindowEx(childHandle, IntPtr.Zero, "ComboBoxEx32", IntPtr.Zero);
                    if (childHandle != IntPtr.Zero)
                    {
                        // get a handle to combo box
                        childHandle = FindWindowEx(childHandle, IntPtr.Zero, "ComboBox", IntPtr.Zero);
                        if (childHandle != IntPtr.Zero)
                        {
                            //get handle to edit
                            childHandle = FindWindowEx(childHandle, IntPtr.Zero, "Edit", IntPtr.Zero);
                            if (childHandle != IntPtr.Zero)
                            {
                                // now to get the URL we need to get the Text - but first get the length of the URL
                                int length = SendMessage(childHandle, WM_GETTEXTLENGTH, 0, 0);
                                length += 1;    // because the length returned above included 0
                                StringBuilder text = new StringBuilder(length); // need stringbuilder - not string
                                int hr = SendMessage(childHandle, WM_GETTEXT, length, text); // get the URL
                                strURL = text.ToString();
                            }
                        }
                    }
                }

现在您已经访问了url,发送一个HTTP Get请求,您将获得纯文本形式的站点源代码。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4059062

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档