question

moondaddy-8531 avatar image
0 Votes"
moondaddy-8531 asked YuZhou-MSFT edited

Microsoft.Edge.SeleniumTools: Assign a custom proxy

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

ms-edge
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @moondaddy-8531
Which version of Edge you're trying to automate? Which version of Selenium you are using?
If you're using Edge Chromium, I think you can use edgeOptions.AddArgument("--user-agent=xxx") and edgeOptions.AddArgument("--proxy-server=xxx") to set the proxy and user agent.

0 Votes 0 ·

Hi @YuZhou-MSFT , I am using Edge Chromium and thank you. I will look into that. Also, I have a post asking about mulit-threading with the same tool here. Can you please take a look?

Thank you


0 Votes 0 ·

1 Answer

YuZhou-MSFT avatar image
0 Votes"
YuZhou-MSFT answered YuZhou-MSFT edited

Hi @moondaddy-8531

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:password@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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.