Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using OpenQA.Selenium;
- using OpenQA.Selenium.Chrome;
- using System;
- class Program
- {
- static void Main()
- {
- ChromeOptions options = new ChromeOptions();
- // Set up the ChromeDriver instance with proxy configuration using AddArgument
- options.AddArgument("--proxy-server=http://71.86.129.131:8080");
- // Set up the ChromeDriver instance
- IWebDriver driver = new ChromeDriver(options);
- // Create the NetworkAuthenticationHandler with credentials
- var networkAuthenticationHandler = new NetworkAuthenticationHandler
- {
- UriMatcher = uri => uri.Host.Contains("ident.me"), // Only apply for the specific host
- Credentials = new PasswordCredentials("your_proxy_username", "your_proxy_password")
- };
- // Add the authentication credentials to the network request
- var networkInterceptor = driver.Manage().Network;
- networkInterceptor.AddAuthenticationHandler(networkAuthenticationHandler);
- // Navigate to target website
- driver.Navigate().GoToUrl("http://ident.me");
- // Add a wait for three seconds
- Thread.Sleep(3000);
- // Select the HTML body
- IWebElement pageElement = driver.FindElement(By.TagName("body"));
- // Get and print the text content of the page
- string pageContent = pageElement.Text;
- Console.WriteLine(pageContent);
- // Close the browser
- driver.Quit();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement