![](/img/trans.png)
[英]C# Selenium WebDriver FireFox Profile - using proxy with Authentication
[英]C# Selenium using proxy with chrome's profile
我想用我的個人資料和代理打開Chrome。 這段代碼改變了我的IP:
string IPtoUse = richTextBox2.Lines[0];
ChromeOptions options = new ChromeOptions();
/*options.AddArguments("user-data-dir=C:\\Users\\Kamil\\AppData\\Local\\Google\\Chrome\\User Data");*/
var proxy = new Proxy();
proxy.Kind = ProxyKind.Manual;
proxy.IsAutoDetect = false;
proxy.HttpProxy =
proxy.SslProxy = IPtoUse;
options.Proxy = proxy;
options.AddArgument("ignore-certificate-errors");
var Driver = new ChromeDriver(options);
Driver.Navigate().GoToUrl("https://www.iplocation.net/find-ip-address");
當我添加行:
options.AddArguments("user-data-dir=C:\\Users\\Kamil\\AppData\\Local\\Google\\Chrome\\User Data");
程序啟動時忽略代理。 我究竟做錯了什么? 我也想問你們我該如何改變這條線:
System.Threading.Thread.Sleep(2000);
使程序暫停但不要凍結它。 感謝幫助!
由於用戶數據行,這可能對您造成錯誤。 應該如下:
options.AddArguments("--user-data-dir=C:\\Users\\Kamil\\AppData\\Local\\Google\\Chrome\\User Data");
暫停的問題是暫停主線程,您必須創建另一個線程並將所有代碼放在該線程上。
public static void DoWork()
{
//put all your code in here, and you then you can pause it without it freezing
}
public static void StartWorker()
{
Thread worker = new Thread(DoWork);
worker.IsBackground = true;
worker.SetApartmentState(System.Threading.ApartmentState.STA);
worker.Start()
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.