Advertisement
dereksir

Untitled

Oct 16th, 2023 (edited)
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.20 KB | None | 0 0
  1. using PuppeteerSharp;
  2. using System;
  3. using System.Threading.Tasks;
  4.  
  5. class Program
  6. {
  7.     static async Task Main(string[] args)
  8.     {
  9.         // Initialize a browser fetcher to download PuppeteerSharp binaries
  10.         using var browserFetcher = new BrowserFetcher();
  11.         await browserFetcher.DownloadAsync();
  12.  
  13.         // Launch a headless browser instance with specified options
  14.         await using var browser = await Puppeteer.LaunchAsync(new LaunchOptions
  15.         {
  16.             Headless = true, // Run the browser in headless mode (no GUI)
  17.             Args = new[] { "--proxy-server=8.219.97.248:80" } // Configure the proxy server
  18.         });
  19.  
  20.         // Create a new web page
  21.         await using var page = await browser.NewPageAsync();
  22.  
  23.         // Navigate to target URL using the configured proxy (no proxy authentication in this code)
  24.         await page.GoToAsync("https://httpbin.io/ip");
  25.  
  26.         // Retrieve the content of the web page
  27.         var pageContent = await page.GetContentAsync();
  28.  
  29.         // Print the page content (in this case, the IP address)
  30.         Console.WriteLine(pageContent);
  31.  
  32.         // Close the browser when finished
  33.         await browser.CloseAsync();
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement