单击按钮后,Webrowser控制c#WAIT [英] Webrowser control c# WAIT after click on button

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

问题描述

您好。我有很大的问题请帮忙。



我正在废弃网站,页面没有分页。如果您想转到下一页,则需要单击表单按钮或从选择选项菜单中选择。使用webbrowser控件我点击按钮或选择选项如下:



HtmlElement reportDropDown = webBrowser1.Document.GetElementById(ctl00_ContentPlaceHolderProductDisplay_wuc_product_display_ddlTopPage);

reportDropDown.SetAttribute(value,Convert.ToString(c));

reportDropDown.InvokeMember(onchange);





问题是:当我废弃第一页并点击按钮时,点击按钮后页面会有一些小动画加载到同一页面上,同时转到下一页。单击按钮并开始加载动画时,while循环中的代码不会等待,所以再次从第一页开始报废相同的结果。



我已经尝试过webbrowser1.readystate,isbusy或者类似的,他们没有为按钮工作!!!!

我点击按钮时需要等待机制!!!



我的while循环的小演示:



while(i< = 10)//页数

{

while(...)

{

//这里我正在抓取当前页面的数据

}

//这里点击按钮

++ i;

//这里我需要一些机制等待

}

解决方案

为什么要借助Web浏览器抓取网站?这是一些客户端UI,Web报废与它无关。请参阅:

http://en.wikipedia.org/wiki/Web_scraping [< a href =http://en.wikipedia.org/wiki/Web_scrapingtarget =_ blanktitle =New Window> ^ ]。



对于报废,你需要的主要是类 HttpWebRequest 。详情请见我过去的答案:

从网页获取特定数据 [ ^ ],

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



- SA

Hi. I have very big problem please help.

I'm scrapping website and the page don't have pagination. If you like to go to the next page you need to click on form button or select from the select option menu. With webbrowser control I'm clicking on the button or the select option like this:

HtmlElement reportDropDown = webBrowser1.Document.GetElementById("ctl00_ContentPlaceHolderProductDisplay_wuc_product_display_ddlTopPage");
reportDropDown.SetAttribute("value", Convert.ToString(c));
reportDropDown.InvokeMember("onchange");


The problem is: when I scrap the first page, and the button is clicked, after clicking the button the page have some little animation with loading on the same page, while go to the next page. When the button is clicked and the loading animation is start, my code in the while loop don't wait, so start scrapping again the same results from the first page.

I've tried webbrowser1.readystate, isbusy or similar, they not working for button!!!!
I need waiting mechanism when button is clicked!!!

little demo of my while loop:

while(i <= 10) // number of pages
{
while(...)
{
//here i'm scraping data for the current page
}
// here goes button click
++i;
// here i need some mechanism for waiting
}

解决方案

Why would you scrape Web sites with the help of a Web browser? This is some client UI, and Web scrapping has nothing to do with it. Please see:
http://en.wikipedia.org/wiki/Web_scraping[^].

For scrapping, the main thing you need is the class HttpWebRequest. For further detail, please see my past answers:
get specific data from web page[^],
How to get the data from another site[^].

—SA


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

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