Original Article C # capture the content of the Ajax page
A considerable part of the current web pages use Ajax technology. The so-called Ajax technology is event-driven (of course, this may be not comprehensive). After you submit a URL, not all pages are sent to you by the server, but most of them are JS scripts, represented by the <JavaScript tag, some of which are linked to external JS files, some are built-in JS scripts that are executed only after the client loads the source code sent from the server. Therefore, neither WebClient nor httprequest in C # can get the correct results, because these scripts are executed only after the server sends them!
However, it is normal to use IE to browse the page, so only one solution is to use the webbrowser control.
However, when using webbrowser, you will find that in the downloadcomplete event, you cannot know when the page is actually loaded!
Of course, a webpage with a frame may trigger complete multiple times, even if you use the counter method, that is, in the navigated event ++, but in downloadcomplete --, I still cannot get the result after JS execution is complete. I also felt very strange at first, until Gg learned about the relevant Ajax article and understood the original article.
The final solution is to use webbrowser + timer to capture pages.
The key is still the page status. We can use webbrowser1.statustext. If "finished" is returned, the page is loaded!
The sample code is as follows:
Private void timereffectick (Object sender, eventargs E)
{
Webbrowser1.navigate (URL );
If (webbrowser1.statustext = "")
{
Timer1.enabled = false;
// Page loading is complete and other tasks are performed.
}
}