How to Read HTML from Browser Class
Time to write new codes again, this portion of my website was stopped when I lost my VPS servers a few months back. Coderinthebox won’t be called as such without code examples.
This tiny code will show a trick to load a dynamic web browser, navigate it and extract the page’s html code purely on the backend.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
// Create a dynamic Webbrowser to get the HTML Source code from a given URL public String ReadViaBrowser(String url) { // Instantiate the browser Browser wb = new Browser(); // Tell the browser to visit the url wb.Navigate(url); // Wait for the browser to load the complete website while (wb.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); } // DocumentText holds the html code return wb.DocumentText; } |