Use C # To capture Ajax page content

Source: Internet
Author: User
A considerable portion of the current web pages are used Ajax Technically, neither WebClient nor httprequest in C # can get the correct results, because these scripts are executed after the server sends them!

However, it is normal when we use IE to browse the page, so only one solution is to useWebbrowserWidget

HoweverWebbrowserYou 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 --, still cannot get the result after JS execution is complete, and I also felt very strange at first, until ggAjaxOfArticle, Understand the original committee.

The final solution is to useWebbrowser+ Timer to solve the page grabbing Problem
The key is still the page status. We can use webbrowser1.statustext. If "finished" is returned, the page is loaded!

ExampleCodeAs follows:

Private   Void Timereffectick ( Object Sender, eventargs E)
{

Textbox1.text + = Webbrowser1.statustext;
If (Webbrowser1.statustext =   " Complete " )
{

Timer1.enabled =   False ;
// Page loading is complete. Do some other things
Textbox1.text + = Webbrowser1.document. Body. outerhtml;
// Do not use webbrowser1.documenttext. This is the same as viewing source files.
}
}
Private   Void Form1_load ( Object Sender, eventargs E)
{
String URL =   " Http://cd.mei8.cn/face/work/windex.aspx? BTN = 6 " ;
Webbrowser1.navigate (URL );
}


Put three controls,Webbrowser, Timer, textbox
Set 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.