Use C # To capture Ajax page content

Source: Internet
Author: User

A considerable portion of the current web pages use Ajax technology. Neither WebClient nor httprequest in C # can produce correct results, because these scripts are executed only after the server has sent 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) {textbox1.text + = webbrowser1.statustext; If (webbrowser1.statustext = "finished") {timer1.enabled = false; // page loading is complete, do other things: textbox1.text + = webbrowser1.document. body. outerhtml; // webbrowser1.documenttext do not use this, this is the same as viewing the source file} private void form1_load (Object sender, eventargs e) {string url = "http://cd.mei8.cn/face/work/windex.aspx? BTN = 6 "; webbrowser1.navigate (URL );}

  

  


Set three controls, webbrowser, timer, and textbox timer to available.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.