Advertisement
dereksir

Untitled

Nov 6th, 2023 (edited)
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.42 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.         ChromeOptions options = new ChromeOptions();
  10.  
  11.         // Set up the ChromeDriver instance with proxy configuration using AddArgument
  12.         options.AddArgument("--proxy-server=http://71.86.129.131:8080");
  13.  
  14.         // Set up the ChromeDriver instance
  15.         IWebDriver driver = new ChromeDriver(options);
  16.  
  17.         // Create the NetworkAuthenticationHandler with credentials
  18.         var networkAuthenticationHandler = new NetworkAuthenticationHandler
  19.         {
  20.             UriMatcher = uri => uri.Host.Contains("ident.me"), // Only apply for the specific host
  21.             Credentials = new PasswordCredentials("your_proxy_username", "your_proxy_password")
  22.         };
  23.  
  24.         // Add the authentication credentials to the network request
  25.         var networkInterceptor = driver.Manage().Network;
  26.         networkInterceptor.AddAuthenticationHandler(networkAuthenticationHandler);
  27.  
  28.         // Navigate to target website
  29.         driver.Navigate().GoToUrl("http://ident.me");
  30.  
  31.         // Add a wait for three seconds
  32.         Thread.Sleep(3000);
  33.  
  34.         // Select the HTML body
  35.         IWebElement pageElement = driver.FindElement(By.TagName("body"));
  36.  
  37.         // Get and print the text content of the page
  38.         string pageContent = pageElement.Text;
  39.         Console.WriteLine(pageContent);
  40.  
  41.         // Close the browser
  42.         driver.Quit();
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement