C# selenium 设置代理IP和常用参数设置
var cdSvc = ChromeDriverService.CreateDefaultService(); cdSvc.HideCommandPromptWindow = true; //IWebDriver driver = new ChromeDriver(System.AppDomain.CurrentDomain.BaseDirectory.ToString()); var option = new ChromeOptions(); // option.AddArgument("--incognito"); // 影身模式 //option.AddArgument("headless");//设为无头模式 option.AddArgument("disable-infobars");//去掉提示:Chrome正收到自动测试软件的控制 option.AddArguments("--proxy-server=http://192.168.0.1:1123");
//这种设置无效 //option.AddArguments("--proxy-server=http://117.21.178.7:12150"); option.AddArguments("lang=zh_CN.UTF-8"); option.AddExcludedArgument("enable-automation"); option.AddAdditionalCapability("useAutomationExtension", false); //设置代理IP ip+port string ip =192.168.0.1:1123 Proxy proxy = new Proxy(); proxy.Kind = ProxyKind.Manual; proxy.IsAutoDetect = false; proxy.HttpProxy = ip; // proxy.HttpProxy =ip; //这里是http //proxy.SslProxy = ip; //这里是ssl option.Proxy = proxy; option.AddArgument("ignore-certificate-errors"); driver = new ChromeDriver(cdSvc, option);
文章属于个人工作备忘录,欢迎指正...