Last active
October 12, 2022 13:04
-
-
Save sphingu/5781036 to your computer and use it in GitHub Desktop.
Using WebBrowser in WPF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
---------------------------------------------------- | |
// Using WebBrowser for Crowling in WPF | |
---------------------------------------------------- | |
<WebBrowser Cursor="Arrow" Name="MyBrowser" LoadCompleted="MyBrowser_OnLoadCompleted" /> | |
---------------------------------------------------- | |
// useful methods of WebBrowser | |
---------------------------------------------------- | |
MyBrowser.Navigate(new Uri("http://google.com")); | |
private void MyBrowser_OnLoadCompleted(object sender,NavigationEventArgs e) | |
{ | |
... | |
// return source of loaded page in WebBrowser | |
var document=(IHTMLDocument3) MyBrowser.Document; | |
//Get Element and set its value | |
document.getElementById("userName").setAttribute("value","myusername"); | |
//get Button on page and fire its click event | |
document.getElementById("btnSubmit").click(); | |
// Invoke javascript function on page loaded on WebBrowser | |
MyBrowser.InvokeScript("submitform",param1,param2,...); | |
//get data from table in page | |
_innerHtmldata = | |
((IHTMLDocument3) MyBrowser.Document).getElementById("datatable") | |
.innerHTML; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i get error on IHTMLDocument3
could not be found
????? solution???