Advertisement
dereksir

Untitled

Nov 6th, 2023 (edited)
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.37 KB | None | 0 0
  1. using OpenQA.Selenium;
  2. using OpenQA.Selenium.Chrome;
  3. using System;
  4.  
  5. class Program
  6. {
  7.     static void Main()
  8.     {
  9.         var proxies = new List<string>
  10.         {
  11.             "http://211.193.1.11:80",
  12.             "http://138.68.60.8:8080",
  13.             "http://209.13.186.20:80"
  14.             // Add more proxy configurations as needed
  15.         };
  16.  
  17.         // Select a random proxy configuration
  18.         var random = new Random();
  19.         int randomIndex = random.Next(proxies.Count);
  20.         string randomProxy = proxies[randomIndex];
  21.  
  22.         // Create a new ChromeOptions instance
  23.         ChromeOptions options = new ChromeOptions();
  24.  
  25.         // Assign proxy to chrome instance using AddArgument
  26.         options.AddArgument($"--proxy-server={randomProxy}");
  27.         options.AddArgument("headless");
  28.  
  29.         // Set up the ChromeDriver instance
  30.         IWebDriver driver = new ChromeDriver(options);
  31.  
  32.         // Navigate to target website
  33.         driver.Navigate().GoToUrl("http://ident.me");
  34.  
  35.         // Add a wait for three seconds
  36.         Thread.Sleep(3000);
  37.  
  38.         // Select the HTML body
  39.         IWebElement pageElement = driver.FindElement(By.TagName("body"));
  40.  
  41.         // Get and print the text content of the page
  42.         string pageContent = pageElement.Text;
  43.         Console.WriteLine(pageContent);
  44.  
  45.         // Close the browser
  46.         driver.Quit();
  47.  
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement