Browse and retrieve DOM objects via getElement without using WebBrowser

2

Is there any way to navigate web pages, create .Document.getElementById(" ") requests without the need to use the WebBrowser() component on my form?

WebBrowser browser = new WebBrowser();
browser.Navigate("http://");
//[...]
var valor = browser.Document.getElementById("");

Ideally perform the navigations and requisitions, without the need of the system perform the rendering of the web page.

The idea is to get pages loaded as fast as possible , to access a very large and sequential number of pages, retrieving your information in specific IDs.

In addition, is there any way to expect full page loading to be performed before creating the getElementById request, without using (for WebBrowser ):

while (browser.ReadyState != WebBrowserReadyState.Complete) {
    Application.DoEvents();
}
    
asked by anonymous 20.09.2018 / 21:50

1 answer

1

You can download the content of the page using WebClient or HttpClient, read the content and get only the value that you want. You can do this, for example, by using the HtmlAgilityPack . The example below is to get the title of a page, but it can also be done in other ways, perhaps simpler.

string url = "http://www.google.com";
HtmlWeb web = new HtmlWeb();
HtmlDocument doc = web.Load(url);
string tituloGoogle = doc.DocumentNode.ChildNodes["html"].ChildNodes["head"].ChildNodes["title"].InnerHtml;
    
22.09.2018 / 17:13