mshtml

HTML traversal is very slow

半世苍凉 提交于 2019-12-10 11:16:57
问题 I faced that simply iterating through MSHTML elements using C# is horribly slow. Here is small example of iteration through document.all collection three times. We have blank WPF application and WebBrowser control named Browser: public partial class MainWindow { public MainWindow() { InitializeComponent(); Browser.LoadCompleted += DocumentLoaded; Browser.Navigate("http://google.com"); } private IHTMLElementCollection _items; private void DocumentLoaded(object sender, NavigationEventArgs e) {

DocumentComplete event in Embedded IWebBrowser2 using write() method

不问归期 提交于 2019-12-10 08:31:27
问题 I've been looking hard for this but still have not found any solution. I'm using native win32 c++ (no MFC, ATL or .NET) I'm loading an html document with IHTMLDocument2->write(). I would like to get the event when the page is ready to show, meaning that all images and elements are downloaded and rendered. Following the embedded browser object from here embedded web control (IWebBrowser2), embedded javascript's onkeydown and onkeyup not firing and from here http://www.codeproject.com/Articles

MSHTML HTMLHeadElementClass COM Error

≯℡__Kan透↙ 提交于 2019-12-09 02:04:38
问题 I'm currently working with MS HTML to insert a JavaScript code into websites. I made a reference to Microsoft HTML Object Library and types this code. IHTMLDocument2 doc = BrowserHost.Document as HTMLDocumentClass; IHTMLElement head = (IHTMLElement) ((IHTMLElementCollection)doc.all.tags("head")).item(null, 0); IHTMLScriptElement scriptObject = (IHTMLScriptElement)doc.createElement("script"); scriptObject.type = @"text/javascript"; scriptObject.text = TTS.TTSWebFactory.GetJavascript(); (

How can we use MSHTML with VBA?

人走茶凉 提交于 2019-12-08 17:28:34
问题 I saw a lot of examples in MSDN on how to use MSHTML in VS. Have anyone known if and how we can use MSHTML and VBA to open web pages? Thanks. 回答1: In the VBA editor, you go under Tools -> References and add a reference to the Microsoft HTML Object Library [MSHTML.TLB]. Here is a link with an example in VBA. 来源: https://stackoverflow.com/questions/619148/how-can-we-use-mshtml-with-vba

How to get the page source from an IE window?

霸气de小男生 提交于 2019-12-08 14:01:53
问题 I need to parse the page source as rendered by IE. I can use the following simple code to open an IE to a URL. (The BrowserWinodw type is from the Visual Studio Coded UI test framework.) BrowserWindow bw = BrowserWindow.Launch(url); How to get the page source from the IE window? Thanks! 回答1: I have figured out a way to do it. Use the IHtmlDocument2 interface. With reference to this article: http://support.microsoft.com/kb/292485 I will share my code snippet shortly. 来源: https://stackoverflow

IDocHostUIHandler crashing MSHTML.dll with error 0xc0000409

送分小仙女□ 提交于 2019-12-08 13:43:25
问题 I am using slightly modified IDocHostUIHandler from https://stackoverflow.com/a/21699086/592212 in simple one main window test application with only WPF WebBrowser component in that Window. The initialization code is as follows: public MainWindow() { InitializeComponent(); _wbHostHandler = new WebBrowserHostUIHandler(PART_WebBrowser); _wbHostHandler.Flags |= HostUIFlags.DpiAware; PART_WebBrowser.Navigate("SOME_URL"); } There is really nothing else going on in the Application. Still, after

MSHTML : Calling member of javascript object?

≡放荡痞女 提交于 2019-12-08 13:02:09
问题 Using the .NET WebBrowser control, it is fairly simple to execute a member of an HtmlElement. Assuming there is a JavaScript object called "player" with a member called "getLastSongPlayed"; calling this from the .NET WebBrowser control would go something like this: HtmlElement elem = webBrowser1.Document.getElementById("player"); elem.InvokeMember("getLastSongPlayed"); Now my question is: How do I accomplish that using mshtml ? Thanks in advance, Aldin EDIT: I got it up and running, see my

How open internet explorer window, navigate it on url and get her document(HTMLDocument or InternetExplorer) using c# and mshtml library

*爱你&永不变心* 提交于 2019-12-08 07:43:00
问题 How open internet explorer window or tab, navigate it and get her document(HTMLDocument or InternetExplorer) using c# and mshtml library. The type of IE object should be HTMLDocument or InternetExplorer. 回答1: If you want an interactive-automated instance of IE add a (COM) reference to Microsoft Internet Controls ; private void Form1_Load(object sender, EventArgs e) { var IE = new SHDocVw.InternetExplorer(); IE.NavigateComplete2 += new SHDocVw.DWebBrowserEvents2_NavigateComplete2EventHandler

How to get HTML element coordinates using C#?

≯℡__Kan透↙ 提交于 2019-12-08 04:36:12
问题 I am planning to develop web crawler, which would extract coordinates of html elements from web pages. I have found out that it is possible to get html element coordinates by using "mshtml" assembly. Right now I would like to know if it is possible and how to get only necessary information (html,css) from web page, and then by using appropriate mshtml classes get correct coordinates of all html elements? Thank you! 回答1: I use these c# functions to determine element positions. You need to pass

Handling an OnClick event of a checkbox

时光总嘲笑我的痴心妄想 提交于 2019-12-08 02:22:07
问题 I'm trying to handle click events of a checkbox control from a BHO. Here is my code: void STDMETHODCALLTYPE CMyBHO::OnDocumentComplete(IDispatch *pDisp, VARIANT *pvarURL) { // ... InitPage(pDocument); } void CMyBHO::InitPage(IHTMLDocument2 *pDocument) { CComQIPtr<IHTMLDocument3> document3 = pDocument; CComPtr<IHTMLElement> elementCheckbox; document3->getElementById(CComBSTR(L"checkbox_id_here"), &elementCheckbox); if(!elementCheckbox) return; if(!m_fCheckboxAdvised) { // Register to sink