HTMLAgilityPack get AJAX value

ajax asp.net-ajax html-agility-pack

Question

I am trying to get the value of a timer using the HtmlAgilityPack however when I get the innerText by the element ID it returns --:--:--

Is there any way to get the time value since it uses AJAX?

Accepted Answer

The thing is that when you load an HttpAgilityPack.HtmlDocument (from the web, of course), it makes an HTTP web request to the website, and what you receive is plain text. No AJAX/JavaScript or images are loaded. When you see it in a browser, you don't realize about it, because it's a browser ;). After it receives the response, it starts loading images, animations, and executing javascript code, but HtmlAgilityPack uses HttpWebRequest to get the source, and it doesn't manage any javascript code.

I suggest you to download a really brilliant tool to inspect HTTP traffic in your network: Fiddler2. It will allow you to set breakpoints, and see exactly how the response is returned, and you will see that those things are really handled by the browser itself.

I don't really know what is the purpose of getting the time value of a timer in AJAX, but I think you could use WaTiN to load the source using Internet Explorer (and hidding it, because if not, an IE window will appear on the screen loading the page), and in the moment you need to get the value of the timer, get the source from WaTiN and load an HtmlDocument using LoadHtml(string html).




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why