使用WebBrowser 抓取运行js后html页面

private static void Delay(int Millisecond)
        {
            DateTime current = DateTime.Now;
            while (current.AddMilliseconds(Millisecond) > DateTime.Now)
            {

               System.Windows.Forms.Application.DoEvents();
            }
            return;
        }
View Code
public string GetWebContent(string Url)
        {
            WebBrowser wb = new WebBrowser();
            wb.ScriptErrorsSuppressed = true;
            string xmlStr = string.Empty;
            wb.Navigate(Url);
            while (true)
            {
                Delay(2000);//延迟50毫秒
                if (wb.ReadyState == WebBrowserReadyState.Complete)//判断文档是否加载完毕
                {
                    if (!wb.IsBusy)
                    {
                        //在这里获取你想要的内容
                    }
                }
                continue;
            }
        }
View Code

需要在页面顶部 page标签加入   AspCompat="true"

posted @ 2020-02-21 10:19  尧叶  阅读(531)  评论(0编辑  收藏  举报