Microsoft.Edge.SeleniumTools: Assign a custom proxy

moondaddy 916 Reputation points
2021-04-28T21:35:36.027+00:00

I have an app using Microsoft.Edge.SeleniumTools and the HtmlAgilityPack so scrape pages. Is it possible to assign a custom proxy to the request? I have a list of proxies I want to use for 'rotating proxies'.

also, it is possible to assign a different user agent to the header?

If so, how can I do these. i don't see it documented anywhere

Microsoft Edge Microsoft Edge development
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2021-05-05T08:19:34.437+00:00

    Hi @moondaddy

    As you say you're using Edge Chromium, you can use edgeOptions.AddArgument("--user-agent=xxx") and edgeOptions.AddArgument("--proxy-server=xxx") to set the proxy and user agent.

    Example code (please note to change the values to your owns):

    static void Main(string[] args)  
    {  
            EdgeOptions edgeOptions = new EdgeOptions();  
            edgeOptions.UseChromium = true;  
            edgeOptions.BinaryLocation = @"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe";  
            // Here we try to set Firefox user agent...  
            edgeOptions.AddArgument("--user-agent=mozilla/5.0 (windows nt 10.0; win64; x64; rv:78.0) gecko/20100101 firefox/78.0");   
            edgeOptions.AddArgument("--proxy-server=http://user:******@yourProxyServer.com:8080");  
            IWebDriver driver = new EdgeDriver(@"D:\your_webdriver_path", edgeOptions);  
            driver.Navigate().GoToUrl("http://www.yourwebsite.com");  
    }  
    

    Reference link:

    1. Useragent setting in Edge Webdriver
    2. Command-line options for proxy settings

    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Regards,
    Yu Zhou

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.