I am trying to create a program in C# in Visual Studio which would acquire html source of a current opened (or selected, or all) tab(s) in Internet Explorer 8/ (prefered) 9. I am tired of copying by - browser-> View Source, alt+a, alt+c, program -> alt+v Anyone got an idea how to solve it?
A:
Well, there's no easy solution for this I think Maybe you should continue copy and pasting. Anyway, this is what I found surfing the web: (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();
}
}
}
}
Now that you have accessed the url, send an HTTP Get Request you will get the site source in plain text.
Kamyar
2010-10-30 14:24:28
This is a really nice piece of code - So if You can ask explorer for an url, why not ask it for the source?
Miszka.info
2010-10-30 14:32:26
@Miszka: I'm googling to see if that's possible...
Kamyar
2010-10-30 14:34:32
Futhermore ie is devided in Frame Tabs (from spy++) - each window Frame Tab has a window TabWindowsClass which has a Window Shell DocObject View which has a window Internet Explorer_Server
Miszka.info
2010-10-30 14:35:45
@Miszka: The best I could find uses something called Band Objects. http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/415f8b61-7db4-48ab-ab5c-71721afac718 Which is hosted on CodeProject...Which is down for a few hours. Check it out when you can. Hope you make it. and let me know if you did.
Kamyar
2010-10-30 15:21:03
@Kamyar This code is very version dependent, unfortunately. It may work in one version of IE, but it'll never work in all.
Athari
2010-10-30 15:25:25
It is possible, I am working on it, will give full code in some time. This code helped me very much! Thank You indeed
Miszka.info
2010-10-30 15:28:32
No problem Miszka. And good luck.
Kamyar
2010-10-30 16:08:45
How to paste additional code here?
Miszka.info
2010-10-30 23:53:54
I'd appreciate if you post a new answer if you found anything useful.
Kamyar
2010-10-31 13:10:07