Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using PuppeteerSharp;
- using System;
- using System.Threading.Tasks;
- class Program
- {
- static async Task Main(string[] args)
- {
- // Define a list of proxy addresses
- var proxies = new List<string>
- {
- "http://34.140.70.242:8080",
- "http://118.69.111.51:8080",
- "http://15.204.161.192:18080",
- "http://186.121.235.66:8080",
- };
- // Generate a random index
- var random = new Random();
- int randomIndex = random.Next(proxies.Count);
- // Select a random proxy using the randomIndex
- string randomProxy = proxies[randomIndex];
- // Launch browser instance with randomProxy
- var browserFetcher = new BrowserFetcher();
- await browserFetcher.DownloadAsync();
- var browser = await Puppeteer.LaunchAsync(new LaunchOptions
- {
- Headless = true,
- Args = new[] { $"--proxy-server={randomProxy}" }
- });
- // Create a new page
- using var page = await browser.NewPageAsync();
- // Navigate to target URL
- await page.GoToAsync("https://httpbin.io/ip");
- // Retreive page content
- var pageContent = await page.GetContentAsync();
- Console.WriteLine(pageContent);
- // Close the browser
- await browser.CloseAsync();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement