Advertisement
dereksir

Untitled

Mar 19th, 2024 (edited)
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.78 KB | None | 0 0
  1. package com.example;
  2.  
  3. // import the required classes
  4. import com.gargoylesoftware.htmlunit.WebClient;
  5. import com.gargoylesoftware.htmlunit.BrowserVersion;
  6. import com.gargoylesoftware.htmlunit.Page;
  7.  
  8. public class Main {
  9.     public static void main(String[] args) {
  10.         // create Chrome Web Client instance
  11.         try (final WebClient webClient = new WebClient(BrowserVersion.CHROME)) {
  12.            
  13.             // navigate to target web page
  14.             Page page = webClient.getPage("https://httpbin.io/ip");
  15.  
  16.             // extract the content as string
  17.             String pageContent = page.getWebResponse().getContentAsString();
  18.  
  19.             // print the content
  20.             System.out.println(pageContent);
  21.         } catch (Exception e) {
  22.             e.printStackTrace();
  23.         }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement