首页 > 解决方案 > 关于 tor selenium C#

问题描述

大家好,我尝试在 C# 中使用 tor 我在网站上找到了一些资源,但我有一些问题请帮助我:

        WebDriverWait Wait;
        IWebDriver Driver;
        String torBinaryPath = @"D:\Tor Browser\Browser\firefox.exe";
        Process TorProcess = new Process();

        TorProcess.StartInfo.FileName = torBinaryPath;
        TorProcess.StartInfo.Arguments = "-n";
        TorProcess.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
        TorProcess.Start();

        FirefoxProfile profile = new FirefoxProfile();
        profile.SetPreference("network.proxy.type", 1);
        profile.SetPreference("network.proxy.socks", "127.0.0.1");
        profile.SetPreference("network.proxy.socks_port", 9150);
        FirefoxOptions options = new FirefoxOptions();
        options.Profile = profile;
        Driver = new FirefoxDriver(options);
        Wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(60));
        Driver.Navigate().GoToUrl(@"http://whatismyipaddress.com/");

问题是在此处输入图像描述

标签: c#selenium-webdriver

解决方案


您需要使用选项而不是配置文件。请检查下面的示例。

FirefoxOptions opt = new FirefoxOptions();
opt.Profile = new FirefoxProfile();
opt.Profile.SetPreference("network.proxy.type", 1);
opt.Profile.SetPreference("network.proxy.socks", "127.0.0.1");
opt.Profile.SetPreference("network.proxy.socks_port", 9150);
this.Driver = new FirefoxDriver(opt);

推荐阅读