简体   繁体   English

WebBrowser控件阻止Ajax

[英]WebBrowser Control blocking ajax

I'm using webbrowser control embeded in a winform in my C# app to do some scraping. 我正在使用嵌入在C#应用程序中winform中的webbrowser控件进行抓取。 The content I'm looking for is dynamically loaded with ajax. 我要查找的内容是用Ajax动态加载的。 However, when I navigate to the page the content won't load unless I have no other code running. 但是,当我导航到页面时,除非没有其他代码在运行,否则不会加载内容。 I tried doing 我试着做

while(webbrowser1.isBusy);

But that's not helping. 但这无济于事。 I also tried pausing the program for a few second to give it time to load 我还尝试将程序暂停几秒钟,以使其有时间加载

Thread.Sleep(2000);

but it's still not loading. 但仍未加载。 If I navigate to the page with no code following, it loads fine. 如果我导航至没有任何代码的页面,则加载正常。 I'm not really sure how I could split this into threads. 我不太确定如何将其拆分为线程。 Any help would be appreciated. 任何帮助,将不胜感激。

while(webbrowser1.isBusy); while(webbrowser1.isBusy); and Thread.Sleep(2000); 和Thread.Sleep(2000); would block the main message pump, and ajax requires a message pump for asynchronous callback. 会阻塞主消息泵,而ajax需要一个消息泵来进行异步回调。 I suggest you to start a timer in DocumentComplete to poll the web page regularly until you think the page is complete. 建议您在DocumentComplete中启动一个计时器,以定期轮询网页,直到您认为该页面完整为止。 Remember to stop the timer in BeforeNavigate2 记住要在BeforeNavigate2中停止计时器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM