Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example;
- // import the required classes
- import com.gargoylesoftware.htmlunit.BrowserVersion;
- import com.gargoylesoftware.htmlunit.Page;
- import com.gargoylesoftware.htmlunit.WebClient;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Random;
- public class Main {
- public static void main(String[] args) {
- // define your proxy list
- List<String> proxyList = new ArrayList<>();
- proxyList.add("129.80.134.71:3128");
- proxyList.add("185.49.170.20:43626");
- proxyList.add("14.177.236.212:55443");
- // create a random number generator
- Random random = new Random();
- // generate a random index to select a proxy from the list
- int randomIndex = random.nextInt(proxyList.size());
- // select random proxy
- String randomProxy = proxyList.get(randomIndex);
- // extract proxy host and port based on the random index
- String PROXY_HOST = randomProxy.split(":")[0];
- int PROXY_PORT = Integer.parseInt(randomProxy.split(":")[1]);
- // create Chrome Web Client instance using specified proxy settings.
- try (final WebClient webClient = new WebClient(BrowserVersion.CHROME, PROXY_HOST, PROXY_PORT)) {
- // navigate to target web page
- Page page = webClient.getPage("https://httpbin.io/ip");
- // extract the content as string
- String pageContent = page.getWebResponse().getContentAsString();
- // print the content
- System.out.println(pageContent);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement