In C # using WebKitBrowser, how to get HTML?

I have been looking for an answer for this all morning and last night.

I use WebKit.NET as an internal browser to mock the reality of the browser, and I followed the tutorial here .

Therefore, when creating a form, I declare:

this.webKitBrowser1.Navigated += new WebBrowserNavigatedEventHandler(webKitBrowser1_Navigated); 

Where in the webKitBrowser1_Navigated event I am trying to get the text of a document using:

 string content = webKitBrowser1.DocumentText; 

But the content is empty .

In addition, I use webkitBrowser because I need a webkit mechanism to get web content.

Any idea on how I can get text content from WebKit Engine? Thanks.

+4
source share
1 answer

Document content (via the DocumentText property) is available when the web bundle engine has finished loading the document. Access to the property will result in an empty DocumentText property in advance.

You must use the DocumentCompleted event to wait for the document to load.

The following code shows how to use the DocumentCompleted event:

 webKitBrowser1.Navigate("www.google.com"); webKitBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webKitBrowser1_DocumentCompleted); void webKitBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { string documentContent = webKitBrowser1.DocumentText; MessageBox.Show(documentContent); } 
+4
source

Source: https://habr.com/ru/post/1392289/


All Articles