Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ch11.readWebpage;
- import java.io.IOException;
- import java.net.URL;
- import java.util.Scanner;
- /**
- * A program that scans a webpage and prints out the links url.
- */
- public class WebpageReader {
- public static void main(String[] args) throws IOException {
- URL pageLocation = new URL("http://horstmann.com/index.html");
- Scanner in = new Scanner(pageLocation.openStream());
- while (in.hasNextLine()){
- String line = in.nextLine();
- int to = 0;
- while(line.substring(to).contains("href='http://")) {
- int from = line.substring(to).indexOf("'");
- to = line.substring(to).indexOf("'", from + 1);
- System.out.println(line.substring(from + 1, to));
- }
- }
- }
- }
Advertisement
RAW Paste Data
Copied
Advertisement