Webrowser控制c#c [英] Webrowser control c#c

查看:71
本文介绍了Webrowser控制c#c的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。我正在从一些有分页的网站上删除一些数据。我遍历了分页中的所有页面,但是当从页面加载某些页面时,页面已满载但代码在我的代码开始抓取数据之前等待了一些。



我的问题是:下面有一个更好的实现,当页面完全加载并在此之后很快开始报废?



Hi. I'm scrapping some data from some website which have a pagination. I traverse through all pages in the pagination, but when some page is load from the pagination the page is full loaded but the code is waiting a little more before my code start scraping the data.

My question is: Is there is some better implementation then this one below, when the page is completely loaded and quickly after that to start the scrapping?

webBrowser1.Navigate("javascript:changeCar('"+br+"')");
while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
{
    Application.DoEvents();
}





问题在于Application.DoEvents()使代码等待....



谢谢,干杯



The problem is with Application.DoEvents() which make the code to wait....

Thanks, Cheers

推荐答案

对于 Web抓取,您应该使用类 System.Net.HttpWebRequest 。嗯,它实际上要好几百万,因为Web浏览器与问题无关。



请查看我过去的答案:

如何从其他网站获取数据 [ ^ ],

获取来自网页的具体数据[ ^ ]。



-SA
For Web scraping, you should rather use the class System.Net.HttpWebRequest . Well, it is actually millions times better, as a Web browser is majorly irrelevant to the problem.

Please see my past answers:
How to get the data from another site[^],
get specific data from web page[^].

—SA


你会最好使用 WebBrowser.DocumentCompleted [ ^ ]事件 - 然后在等待页面加载时你不需要执行任何循环。



最好的问候

Espen Harlinn
You would be better off using the WebBrowser.DocumentCompleted[^] event - then you would not need to perform any loop while waiting for the page to load.

Best regards
Espen Harlinn


@Espen我会将DocumentCompleted放入我的代码中,因为有时候应用程序与Application.DoEvents()分手了。



@Sergey我有时候也会使用httpwebrequest,但是在使用Internet Explorer包装器时我会更舒服一点,我的应用程序的速度不是问题。 :)



谢谢两位。欢迎大家提出新想法。
@Espen I will put DocumentCompleted inside my code, because sometimes the app with Application.DoEvents() broke up.

@Sergey I also use httpwebrequest sometimes, but I'm a little more comfortable when use the internet explorer wrapper, and the speed of my app here is not a problem. :)

Thanks both. New ideas here from everyone are welcome.


这篇关于Webrowser控制c#c的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆