public override SiteCookie GetCookie() { if (string.IsNullOrEmpty(Pattern)) { throw new Exception("Fiddler CookieTrapper: Pattern cannot be null!"); } string cookie; using (FiddlerClient fiddlerWrapper = new FiddlerClient(ProxyPort, Pattern)) { fiddlerWrapper.StartCapture(true); try { base.GetCookie(); var header = fiddlerWrapper.Headers; const string cookiesPattern = @"Cookie: (.*?)\r\n"; cookie = Regex.Match(header, cookiesPattern).Groups[1].Value; } catch (Exception e) { LogCenter.Log(null, "Get cookie failed.", LogLevel.Error, e); return(null); } fiddlerWrapper.StopCapture(); } return(new SiteCookie { CookiesStringPart = cookie }); }
public override string GetCookie() { if (string.IsNullOrEmpty(Pattern)) { throw new Exception("Fiddler CookieTrapper: Pattern cannot be null!"); } string cookie = string.Empty; using (FiddlerClient fiddlerWrapper = new FiddlerClient(ProxyPort, Pattern)) { fiddlerWrapper.StartCapture(true); try { base.GetCookie(); var header = fiddlerWrapper.Headers; const string cookiesPattern = @"Cookie: (.*?)\r\n"; cookie = Regex.Match(header, cookiesPattern).Groups[1].Value; } catch { // ignored } fiddlerWrapper.StopCapture(); } return(cookie); }
public FiddlerDownloader(string urlParten, Option option, int webDriverWaitTime = 200) { _option = option; _option.Proxy = "127.0.0.1:30000"; _webDriverWaitTime = webDriverWaitTime; Task.Factory.StartNew(() => { while (true) { IntPtr maindHwnd = WindowsFormUtil.FindWindow(null, "plugin-container.exe - 应用程序错误"); if (maindHwnd != IntPtr.Zero) { WindowsFormUtil.SendMessage(maindHwnd, WindowsFormUtil.WmClose, 0, 0); } Thread.Sleep(500); } // ReSharper disable once FunctionNeverReturns }); _fiddlerClient = new FiddlerClient(30000, urlParten); _fiddlerClient.StartCapture(); if (_downloader == null) { _downloader = this; } }
protected override Cookies GetCookies(ISpider spider) { if (string.IsNullOrEmpty(Pattern)) { throw new Exception("Fiddler CookieTrapper: Pattern cannot be null!"); } string cookie; using (FiddlerClient fiddlerWrapper = new FiddlerClient(ProxyPort, Pattern)) { fiddlerWrapper.StartCapture(true); try { base.GetCookies(spider); var header = fiddlerWrapper.Headers; const string cookiesPattern = @"Cookie: (.*?)\r\n"; cookie = Regex.Match(header, cookiesPattern).Groups[1].Value; } catch (Exception e) { Logger.MyLog(spider.Identity, "Get cookie failed.", NLog.LogLevel.Error, e); return(null); } fiddlerWrapper.StopCapture(); } return(new Cookies { StringPart = cookie }); }