C# 用Webbrowser 访问动态页面

https://www.cnblogs.com/xuelan/p/11733153.html 

webbrowser错误汇总
https://blog.csdn.net/ZslLoveMiwa/article/details/80616399
public class WebBrowserCrawler { // WebBrowser private WebBrowser _WebBrowder; //最后结果 private string _Result { get; set; } //网址 private string _Path { get; set; } /// <summary> /// 对外公开的Method /// </summary> www.it165.net /// <param name="url">URL Path</param> /// <returns></returns> public string GetReult(string url) { _Path = url; var mThread = new Thread(FatchDataToResult); mThread.SetApartmentState(ApartmentState.STA); mThread.Start(); mThread.Join(); return _Result; } /// <summary> /// Call _WebBrowder 抓取资料 /// For thread Call /// </summary> private void FatchDataToResult() { _WebBrowder = new WebBrowser(); _WebBrowder.Navigate(_Path); while (_WebBrowder.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); } //如果不加下面绿色结果能出来 可以忽略 System.Timers.Timer timer = new System.Timers.Timer(); var isComplete = false; timer.Elapsed += new System.Timers.ElapsedEventHandler((sender, e) => { //加载完毕 isComplete = true; timer.Stop(); }); timer.Interval = 1000 * 5; timer.Start(); //继续等待 5s,等待js加载完 while (!isComplete) Application.DoEvents(); _Result = _WebBrowder.Document.Body.OuterHtml; _WebBrowder.Dispose(); } //结束后回填 } class program { static void Main(string[] args) { WebBrowserCrawler webBrowserCrawler = new WebBrowserCrawler(); string tt=webBrowserCrawler.GetReult("https://rd5.zhaopin.com/resume/email/open?s=be5801f663e64e64894a696fc29a74d5"); Console.ReadKey(); } }

 

posted @ 2019-10-24 16:47  CoderLan  阅读(1682)  评论(0编辑  收藏  举报