200

C#采集网页,模拟点击后无法加载新页面

采集该网址:
http://www.iwencai.com/stockpick/search?typed=1&preParams=&ts=1&f=3&qs=pc_%7Esoniu%7Estock%7Estock%7Ehistory%7Equery&selfsectsn=&querytype=&searchfilter=&tid=stockpick&w=%E6%A6%82%E5%BF%B5%E6%9D%BF%E5%9D%97%EF%BC%8C%E5%9F%8E%E5%B8%82

要求:模拟点击下一页,选择显示70/条每页,(抓包不知是否可获得下一页的地址),我的代码如下,运行后获得的html代码仍为第一页,没有翻页。
public class gWebByWebBrowser
{
WebBrowser web;

HtmlElement btnAdd = null;
public gWebByWebBrowser(){
web = new WebBrowser();

}

    public string GetHtml(string url,  WBrowserPara wBrowserPara){
        //web.DocumentCompleted += web_DocumentCompleted;
        web.Navigate(url);
        while (web.ReadyState != WebBrowserReadyState.Complete) Application.DoEvents();                     
        eventCounter = 0;           
        operation();
        return web.DocumentText;
    }
    void operation(){ // 模拟操作
        HtmlElementCollection Aresults = web.Document.GetElementsByTagName("a");
        foreach (HtmlElement item in Aresults){
            if (item.InnerHtml == "下页") { btnAdd = item; }                 
        }
        btnAdd.InvokeMember("onclick");
              foreach (HtmlElement f in web.Document.GetElementsByTagName("option"))
    {
        if (f.InnerText == @"显示70条/页")
        {
            f.InvokeMember("Click");
            f.SetAttribute("selected", "selected");
        }
    }
        web.Refresh();
        while (web.ReadyState != WebBrowserReadyState.Complete) Application.DoEvents();           
    }
}
查看全部
wuwei2_00_8
Tom20081
2017/02/12 01:58
  • c#
  • webbrowser
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

2个回复