Browse and retrieve DOM objects via getElement without using Webbrowser

Asked

Viewed 82 times

2

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

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

Ideally perform the navigations and requests, without the need for the system to perform the rendering web page.

The idea is to make the loading of the pages as soon as possible, to access a very large and sequential amount of pages, retrieving your information in specific ID elemets.

Also, is there any way to wait for the full page upload to be performed before creating the request getElementById, unused (to the WebBrowser):

while (browser.ReadyState != WebBrowserReadyState.Complete) {
    Application.DoEvents();
}

  • If you don’t have the page loaded, how could you get elements from it? Can you elaborate more on the scenario? When it says "very large and sequential number of pages" it refers more concretely to what?

  • Hello @Joãomartins, I would like to load the page yes, I would just like to know if there is any other way to load pages, access your objects using an alternative to Webbrowser(), because my system will load a page, recover a value from it, go to next page, regain its value... So on. Thank you very much for your help, from now on.

1 answer

1


You can download the content from the page using the Webclient or Httpclient, read the content and take only the value you want. You can do this, for example by using the Htmlagilitypack. The example below is to take 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;
  • Excellent, it was something exactly like this I needed! Thank you very much for your help Ives, it is of great value.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.