Advertisement
piffy

FetchHTML

Oct 31st, 2021
936
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.73 KB | None | 0 0
  1. import java.io.IOException;
  2. import java.io.InputStream;
  3. import java.net.MalformedURLException;
  4. import java.net.URL;
  5.  
  6. public class FetchHTML {
  7.  
  8.     protected  String HTML;
  9.     protected  String theURL;
  10.  
  11.     public FetchHTML(String theURL) throws IOException {
  12.         this.theURL=theURL;
  13.         this.theURL="";
  14.     }
  15.  
  16.     protected void fetch() throws IOException {
  17.          URL url = new URL(theURL);
  18.         InputStream is = url.openStream();
  19.         int ptr = 0;
  20.         StringBuffer buffer = new StringBuffer();
  21.         while ((ptr = is.read()) != -1) {
  22.             buffer.append((char)ptr);
  23.         }
  24.         HTML=buffer.toString();
  25.     }
  26.  
  27.     @Override
  28.     public String toString() {
  29.         return HTML;
  30.     }
  31.  
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement