我正试图在Visual Studio的C#中创建一个程序,该程序将获取Internet Explorer8/(首选) 9中当前打开(或选择,或全部)选项卡的html源代码。我厌倦了通过浏览器复制->查看源代码,alt+a,alt+c,程序-> alt+v有人知道如何解决它吗?
发布于 2010-10-30 22:24:28
这个问题没有简单的解决方案,我想也许你应该继续复制和粘贴。总之,这就是我在网上找到的:(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 Get请求,您将获得纯文本形式的站点源代码。
https://stackoverflow.com/questions/4059062
复制相似问题