1

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

4

1 回答 1

2

好吧,我认为这没有简单的解决方案也许你应该继续复制和粘贴。无论如何,这就是我在网上冲浪时发现的:(http://www.experts-exchange.com/Microsoft/Development/Q_23767759.html

{   // 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 获取请求,您将获得纯文本的站点源。

于 2010-10-30T14:24:28.167 回答