protected void Navi(string url) { if (!GetWebBrowser().InvokeRequired) { pWB.WBDOCDOWNLOADCTLFLAG = (int)m_DLCtlFlags; pWB.Navigate(url); } else { //清空重定向URL容器 m_RedirectUrl.Clear(); //设置连接状态 m_IsNavigationCompleted = false; m_IsNavigationError = false; m_IEErrorCode = 0; //设置时间戳 m_NavigatingStartTimepoint = DateTime.Now; pWB.Invoke(new CsEXWBNaviInvoker(Navi), new object[] { url }); lock (navigatelocker) { Monitor.Wait(navigatelocker, NAVIGATINGOUTOFSECOND * 1000); } Thread.Sleep(200); } }
static void Main(string[] args) { //init browser csExWB.cEXWB pWb = new cEXWB(); pWb.Size = new System.Drawing.Size(800, 600); pWb.WBDOCDOWNLOADCTLFLAG = (int) (DOCDOWNLOADCTLFLAG.NO_SCRIPTS | DOCDOWNLOADCTLFLAG.NO_DLACTIVEXCTLS | DOCDOWNLOADCTLFLAG.NO_JAVA | DOCDOWNLOADCTLFLAG.NO_RUNACTIVEXCTLS | DOCDOWNLOADCTLFLAG.PRAGMA_NO_CACHE | DOCDOWNLOADCTLFLAG.SILENT); pWb.DownloadSounds = false; pWb.DownloadVideo = false; pWb.DocumentComplete += new DocumentCompleteEventHandler(pWb_DocumentComplete); pWb.NavigateError += new NavigateErrorEventHandler(pWb_NavigateError); pWb.WBSecurityProblem += new SecurityProblemEventHandler(pWb_WBSecurityProblem); pWb.BeforeNavigate2 += new BeforeNavigate2EventHandler(pWb_BeforeNavigate2); pWb.NavToBlank(); pWb.Navigate("http://www.google.com"); while (!done) { Application.DoEvents(); System.Threading.Thread.Sleep(100); } //Get the source, the document, .... }
private void DoSomethingWithParameterV2(object x) { var parameter = x as SpiderParameter; if (parameter != null) { foreach (DataRow dr in parameter.DT.Rows) { var rowId = Convert.ToInt32(dr["RowId"]); var url = Convert.ToString(dr["Url"]); var productId = Convert.ToString(dr["ProductId"]); //lock(LockHelper) //{ #region //using (Control c = new Control()) //{ // ExtendedWebBrowser wwb = new ExtendedWebBrowser(); // wwb.ScriptErrorsSuppressed = true; // wwb.IsWebBrowserContextMenuEnabled = false; // wwb.AllowWebBrowserDrop = false; // wwb.ScrollBarsEnabled = false; // c.Controls.Add(wwb); // wwb.BusinessData = productId; // wwb.ThreadId = parameter.ThreadId; // //Loading[parameter.ThreadId] = true; // 表示正在加载 // //wwb.DownloadComplete += new EventHandler(wwb_DownloadComplete); // //wwb.Navigated += wwb_Navigated; // wwb.NewWindow += wb_NewWindow; // wwb.DocumentCompleted += wwb_DocumentCompleted; // wwb.NavigateError += new ExtendedWebBrowser.WebBrowserNavigateErrorEventHandler(wb_NavigateError); // wwb.DownloadControlFlags = (int)WebBrowserDownloadControlFlags.DOWNLOADONLY; // wwb.Navigate(url); // //var tempLoading = Loading[parameter.ThreadId]; // // !wwb.IsDisposed && // while ( wwb.ReadyState != WebBrowserReadyState.Complete) // { // Application.DoEvents(); // 等待本次加载完毕才执行下次循环. // } // if (wwb.ActiveXInstance != null) // { // Marshal.ReleaseComObject(wwb.ActiveXInstance); // } // wwb.Dispose(); // wwb = null; //} #endregion using (csExWB.cEXWB pWb = new cEXWB()) { //pWb.Size = new System.Drawing.Size(800, 600); pWb.WBDOCDOWNLOADCTLFLAG = (int) (DOCDOWNLOADCTLFLAG.NO_SCRIPTS | DOCDOWNLOADCTLFLAG.NO_DLACTIVEXCTLS | DOCDOWNLOADCTLFLAG.NO_JAVA | DOCDOWNLOADCTLFLAG.NO_RUNACTIVEXCTLS | DOCDOWNLOADCTLFLAG.PRAGMA_NO_CACHE | DOCDOWNLOADCTLFLAG.SILENT); pWb.DownloadSounds = false; pWb.DownloadVideo = false; pWb.DownloadActiveX = false; pWb.DownloadImages = false; pWb.DownloadScripts = true; pWb.DocumentComplete += new DocumentCompleteEventHandler(pWb_DocumentComplete); pWb.NavigateError += new NavigateErrorEventHandler(pWb_NavigateError); pWb.WBSecurityProblem += new SecurityProblemEventHandler(pWb_WBSecurityProblem); pWb.BeforeNavigate2 += new BeforeNavigate2EventHandler(pWb_BeforeNavigate2); //pWb.DisableScriptDebugger(); pWb.NavToBlank(); pWb.Navigate(url); while (!done) { Application.DoEvents(); System.Threading.Thread.Sleep(100); } GatherPriceV2(productId, url, pWb.DocumentSource); //pWb.Dispose(); done = false; } //} } } }