How to grab the Contents Which updated by JavaScript WebBrowser

£可爱£侵袭症+ 提交于 2019-12-06 10:41:24
Mohammadreza

I had the same problem. Use the following sample code:

IHTMLDocument2 doc = webBrowser1.Document.DomDocument as IHTMLDocument2;
string content = doc.body.innerText;

Also, add mshtml to the references of your project (if you dont know how to add the refernce, just google it).

Actually, whenever you use this code, the value in the doc variable is the updated version of the contents of the webbrowser.

Good Luck

I would guess that the javascript that is executing on the page which is modifying the content is happening after the DocumentCompleted event; Perhaps you can try a different event such as 'Invalidated'.

The WebBrowser.DocumentText also many not reflect any changes to the DOM, and you may need to navigate the DOM through the WebBrowser.Document property.

http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.document.aspx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!