Advertisement
dereksir

Untitled

Oct 16th, 2023
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.67 KB | None | 0 0
  1. //..
  2.  
  3. static async Task<Browser> LaunchBrowserWithRandomProxy(List<string> proxies)
  4.     {
  5.          // Select a random proxy from the list
  6.         var random = new Random();
  7.         int randomIndex = random.Next(proxies.Count);
  8.        
  9.         string randomProxy = proxies[randomIndex];
  10.  
  11.         // Launch PuppeteerSharp with the selected proxy
  12.         var browserFetcher = new BrowserFetcher();
  13.         await browserFetcher.DownloadAsync();
  14.         var browser = await Puppeteer.LaunchAsync(new LaunchOptions
  15.         {
  16.             Headless = true,
  17.             Args = new[] { $"--proxy-server={randomProxy}" }
  18.         });
  19.  
  20.         return (Browser)browser;
  21.  
  22.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement