C# wie führe ich einen Proxy in Selenium aus?C#

Ein Treffpunkt für C#-Programmierer
Guest
 C# wie führe ich einen Proxy in Selenium aus?

Post by Guest »

Ich habe einen Socks5-Proxy und wenn ich Tests ausführe, funktioniert es einwandfrei, aber wenn ich versuche, es in Selenium auszuführen, funktioniert es nicht.
Ich habe den folgenden Code ausprobiert, aber er hat nicht funktioniert Funktioniert nicht, was kann ich tun?
Ich habe dasselbe mit Javascript versucht, aber es hat nicht funktioniert. Ich habe auch --proxy-server= versucht, aber es hat nicht funktioniert

Code: Select all

class Program
{
static void Main(string[] args)
{
string proxyAddress = "ip:port";
string proxyUser = "username";
string proxyPassword = "pass";
string videoUrl = "https://ip-adresim.net";

Console.WriteLine("İşlem tamamlandı.");

tasks.Add(Task.Run(() => StartBrowserSession(proxyAddress,proxyUser,proxyPassword, videoUrl)));

Task.WaitAll(tasks.ToArray());

Console.WriteLine("Tüm oturumlar tamamlandı.");
}

static void StartBrowserSession(string proxyAddress, string proxyUser, string proxyPassaword, string videoUrl)
{
ChromeOptions options = new ChromeOptions();
Proxy proxy = new Proxy();
proxy.SocksVersion = 5;
proxy.SocksProxy = proxyAddress;
proxy.SocksUserName = proxyUser;
proxy.SocksPassword = proxyPassaword;
options.Proxy=proxy;

options.AddArgument("--disable-gpu");
options.AddArgument("--no-sandbox");
options.AddArgument("--disable-dev-shm-usage");
options.AddArgument("--disable-blink-features=AutomationControlled");
options.AddArgument("--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.5735.110 Safari/537.36");
options.AddUserProfilePreference("profile.default_content_setting_values.images", 2);
IWebDriver driver = new ChromeDriver(options);
driver.`Navigate().GoToUrl(videoUrl);
((IJavaScriptExecutor)driver).ExecuteScript("Object.defineProperty(navigator, 'webdriver', {get: () => undefined});");
}
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post