J'essaie de créer un programme en C# dans Visual Studio qui permettrait d'acquérir la source html d'un ou de plusieurs onglets ouverts (ou sélectionnés, ou tous) dans Internet Explorer 8/(préféré) 9. Je suis fatigué de copier par - navigateur-> Voir Source, alt + a, alt + c, programme -> alt + v Quelqu'un a eu une idée comment le résoudre?Comment faire pour obtenir l'onglet actif IE8/9 html source par C#
1
A
Répondre
2
Eh bien, il n'y a pas de solution facile pour cela, je pense que vous devriez peut-être continuer à copier et coller. Quoi qu'il en soit, ce que je trouve surfer sur le 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();
}
}
}
}
Maintenant que vous avez accédé à l'URL, envoyez un requête HTTP GET, vous obtiendrez la source du site en texte brut.
Ceci est un très bon morceau de code - Donc, si vous pouvez demander à l'explorateur pour une url, pourquoi ne pas demander la source? –
Futhermore ie est divisée en Frame Tabs (à partir de spy ++) - chaque fenêtre Frame Tab a une fenêtre TabWindowsClass qui a une fenêtre Shell DocObject View qui a une fenêtre Internet Explorer_Server –
@Miszka: Le meilleur que j'ai pu trouver utilise quelque chose appelé Band Objects. http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/415f8b61-7db4-48ab-ab5c-71721afac718 Qui est hébergé sur CodeProject ... Qui est en panne pendant quelques heures. Vérifiez-le quand vous le pouvez. J'espère que vous le faites. et laissez-moi savoir si vous l'avez fait. – Kamyar