dogankemal Posted February 8, 2018 Share Posted February 8, 2018 Hi everyone, i have a project at C# and this project about if a any program start a internet explorer_server class, get all html elements. I did a couple program but today i could not do it only one program. But autoit can view at hidden text tab this but i can't. You can see at attachment. So any one can help me ? Thank you Link to comment Share on other sites More sharing options...
jdelaney Posted February 8, 2018 Share Posted February 8, 2018 WinGetHandle _IEAttach embedded option _IEBodyReadHTML consolewrite If you are not using the above, you are not doing it right. Post your script. IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
dogankemal Posted February 8, 2018 Author Share Posted February 8, 2018 2 hours ago, jdelaney said: WinGetHandle _IEAttach embedded option _IEBodyReadHTML consolewrite If you are not using the above, you are not doing it right. Post your script. [23:35, 8.2.2018] Aras Korkmaz: [DllImport("user32.dll", EntryPoint = "GetClassNameA")] public static extern int GetClassName(IntPtr hwnd, StringBuilder lpClassName, int nMaxCount); /delegate to handle EnumChildWindows/ public delegate int EnumProc(IntPtr hWnd, ref IntPtr lParam); [DllImport("user32.dll")] public static extern int EnumChildWindows(IntPtr hWndParent, EnumProc lpEnumFunc, ref IntPtr lParam); [DllImport("user32.dll", EntryPoint = "RegisterWindowMessageA")] public static extern int RegisterWindowMessage(string lpString); [DllImport("user32.dll", EntryPoint = "SendMessageTimeoutA")] public static extern int SendMessageTimeout(IntPtr hwnd, int msg, int wParam, int lParam, int fuFlags, int uTimeout, out int lpdwResult); [DllImport("OLEACC.dll")] public static extern int ObjectFromLresult(int lResult, ref Guid riid, int wParam, ref IHTMLDocument2 ppvObject); public const int SMTO_ABORTIFHUNG = 0x2; public Guid IID_IHTMLDocument = new Guid("626FC520-A41E-11CF-A731-00A0C9082637"); [23:36, 8.2.2018] Aras Korkmaz: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Diagnostics; using System.Runtime.InteropServices; using mshtml; using System.Globalization; using System.Collections; using System.IO; namespace etikEczane.WebBrowserGetHtml { public partial class Form1 : Form { public Form1() { InitializeComponent(); } #region API CALLS [DllImport("user32.dll", EntryPoint = "GetClassNameA")] public static extern int GetClassName(IntPtr hwnd, StringBuilder lpClassName, int nMaxCount); /delegate to handle EnumChildWindows/ public delegate int EnumProc(IntPtr hWnd, ref IntPtr lParam); [DllImport("user32.dll")] public static extern int EnumChildWindows(IntPtr hWndParent, EnumProc lpEnumFunc, ref IntPtr lParam); [DllImport("user32.dll", EntryPoint = "RegisterWindowMessageA")] public static extern int RegisterWindowMessage(string lpString); [DllImport("user32.dll", EntryPoint = "SendMessageTimeoutA")] public static extern int SendMessageTimeout(IntPtr hwnd, int msg, int wParam, int lParam, int fuFlags, int uTimeout, out int lpdwResult); [DllImport("OLEACC.dll")] public static extern int ObjectFromLresult(int lResult, ref Guid riid, int wParam, ref IHTMLDocument2 ppvObject); public const int SMTO_ABORTIFHUNG = 0x2; public Guid IID_IHTMLDocument = new Guid("626FC520-A41E-11CF-A731-00A0C9082637"); #endregion public IHTMLDocument2 document; public List<IHTMLDocument2> docum = new List<IHTMLDocument2>(); private void button1_Click(object sender, EventArgs e) { docum = new List<IHTMLDocument2>(); if (listBox1.SelectedIndex>-1) { string proName = "listBox1.SelectedItem.ToString().Split('-')[1]"; int hwnd = int.Parse(listBox1.SelectedItem.ToString().Split('-')[0]); document = documentFromDOM(proName, hwnd); foreach (var item in docum) { MessageBox.Show((item.body.innerHTML.Length > 250) ? item.body.innerHTML.Substring(0, 250): item.body.innerHTML); } /// check that we have hold of the IHTMLDocument2... /// } } private IHTMLDocument2 documentFromDOM(string proName,int i) { IntPtr hWnd = new IntPtr(i); EnumProc proc = new EnumProc(EnumWindows); EnumChildWindows(hWnd, proc, ref hWnd); return document; } private int EnumWindows(IntPtr hWnd, ref IntPtr lParam) { int retVal = 1; int lngMsg = 0; int lRes; StringBuilder classname = new StringBuilder(2048); GetClassName(hWnd, classname, classname.Capacity); /// check if the instance we have found is Internet Explorer_Server if ((bool)(string.Compare(classname.ToString(), "Internet Explorer_Server") == 0)) { MessageBox.Show(classname.ToString() + " - " + hWnd.ToString()); if (!hWnd.Equals(IntPtr.Zero)) { lngMsg = RegisterWindowMessage("WM_HTML_GETOBJECT"); if (lngMsg != 0) { SendMessageTimeout(hWnd, lngMsg, 0, 0, SMTO_ABORTIFHUNG, 1000, out lRes); if (!(bool)(lRes == 0)) { int hr = ObjectFromLresult(lRes, ref IID_IHTMLDocument, 0, ref document); docum.Add(document); if ((bool)(document == null)) { MessageBox.Show("NoLDocument Found!", "Warning"); } } } } lParam = hWnd; retVal = 10000; } return retVal; } private void button2_Click(object sender, EventArgs e) { listBox1.Items.Clear(); textBox1.Clear(); if (textBox2.Text == "") { foreach (var item in Process.GetProcesses()) { //if (item.MainWindowHandle != IntPtr.Zero) listBox1.Items.Add(item.MainWindowHandle + "-" + item.ProcessName); } } else { foreach (var item in Process.GetProcessesByName(textBox2.Text)) { //if (item.MainWindowHandle != IntPtr.Zero) listBox1.Items.Add(item.MainWindowHandle + "-" + item.ProcessName); } } //SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows(); //string filename; //ArrayList windows = new ArrayList(); //foreach (SHDocVw.InternetExplorer ie in shellWindows) //{ // filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower(); // if (filename.Equals("explorer")) // { // //do something with the handle here // MessageBox.Show(ie.HWND.ToString()); // } //} } private void button3_Click(object sender, EventArgs e) { listBox1.Items.Clear(); textBox1.Clear(); textBox2.Clear(); } } } Link to comment Share on other sites More sharing options...
dogankemal Posted February 8, 2018 Author Share Posted February 8, 2018 2 hours ago, jdelaney said: WinGetHandle _IEAttach embedded option _IEBodyReadHTML consolewrite If you are not using the above, you are not doing it right. Post your script. And if my code is complicate or wrong. Do you show the right way please ( example project, web site, code block bla. bla. ) Link to comment Share on other sites More sharing options...
jdelaney Posted February 8, 2018 Share Posted February 8, 2018 (edited) I don't care how you produce the application that embeds the browser...If you are automating it with autoit, and not using the functions I provided, you are doing something wrong. I suggest you post to a C# forum if you are having problems with the code side of things. The 'text' of a browser is not going to be seen with the spy tool, you need to attach to the browser, and grab what you need from the DOM object. Edited February 8, 2018 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now