Advertisement
hajonnes

Untitled

Jun 23rd, 2022
691
1 day
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package ch11.readWebpage;
  2.  
  3. import java.io.IOException;
  4. import java.net.URL;
  5. import java.util.Scanner;
  6.  
  7. /**
  8.  * A program that scans a webpage and prints out the links url.
  9.  */
  10. public class WebpageReader {
  11.     public static void main(String[] args) throws IOException {
  12.  
  13.         URL pageLocation = new URL("http://horstmann.com/index.html");
  14.         Scanner in = new Scanner(pageLocation.openStream());
  15.         while (in.hasNextLine()){
  16.            String line = in.nextLine();
  17.            int to = 0;
  18.            while(line.substring(to).contains("href='http://")) {
  19.                int from = line.substring(to).indexOf("'");
  20.                to = line.substring(to).indexOf("'", from + 1);
  21.                System.out.println(line.substring(from + 1, to));
  22.            }
  23.        }
  24.     }
  25. }
  26.  
  27.  
Advertisement
RAW Paste Data Copied
Advertisement