Wrox Programmer Forums
|
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 18th, 2007, 12:02 PM
Registered User
 
Join Date: Jan 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Connection URL

Hi,

I'm doing a program to return a keyword search page from google. In the program below the output will be the code of the page (e.g. using the keyword "water"). The problem is that what I want for the output is only the links in separate lines.

How can I do that? Regular Expressions or is there a better method?

Your help will be very useful for me. :-)

Thanks in advance

mp

import java.net.*;

public class ReadGoogle {
public static void main(String[] args) throws Exception {
URL google = new URL("http://www.google.pt/search?hl=pt-PT&q=water&meta=");

BufferedReader in = new BufferedReader(new InputStreamReader(google.openStream()));

String inputLine;

while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
}
 
Old February 21st, 2007, 06:22 AM
Authorized User
 
Join Date: Feb 2007
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, I think regexp is simple and sufficient.

If you need to do more than link extraction, try javax.swing.text.html.parser.DocumentParser






Similar Threads
Thread Thread Starter Forum Replies Last Post
URL Redirect based on given URL somnath.kartic VS.NET 2002/2003 1 August 2nd, 2012 08:21 AM
URL rewriting with URL forwarding mtabyana BOOK: Professional Search Engine Optimization with PHP: A Dev's Guide to SEO ISBN: 978-0-470-10092-9 0 October 22nd, 2007 08:22 AM
open connection in another connection adityamadisetty SQL Server 2000 1 May 4th, 2006 04:56 AM
URL mani_he Pro PHP 11 December 9th, 2004 02:10 AM
extract URL from Favorites (.URL Files) PhilHawks VB.NET 2002/2003 Basics 2 November 2nd, 2004 04:35 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.