在线时间:8:00-16:00
132-9538-2358
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
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(); } }
评论
请发表评论