Web Link List Example In Java

Instructions:

  1. Download and install the latest Java SDK from java.sun.com.
  2. Download HttpUnit from www.httpunit.org.
  3. Compile the code below with javac.
  4. Place all of the .jar files from HttpUnit in your classpath.
  5. Execute the class below with java or javaw.

Source code:

  package com.whatever;

import com.meterware.httpunit.*;

public class GetLinks { public static void main(String[] args) { try { WebLink[] links = new WebConversation().getResponse("http://www.google.com").getLinks(); for (int linkIndex = 0; linkIndex<links.length; linkIndex++) { System.out.println(links[linkIndex].getURLString()); } } catch (Exception e) { e.printStackTrace(); } } }

Output on April 15th, 2004:

  /imghp?hl=en&tab=wi&ie=UTF-8
  /grphp?hl=en&tab=wg&ie=UTF-8
  /nwshp?hl=en&tab=wn&ie=UTF-8
  /froogle?hl=en&tab=wf&ie=UTF-8
  /froogle?hl=en&tab=wf&ie=UTF-8
  /options/index.html
  /advanced_search?hl=en
  /preferences?hl=en
  /language_tools?hl=en
  /ads/
  /services/
  /about.html


EditText of this page (last edited April 15, 2004) or FindPage with title or text search