Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Grabbing HTML source code

2 views
Skip to first unread message

MJ

unread,
Jul 21, 1999, 3:00:00 AM7/21/99
to
I'm writing a java application that needs a certain number located on a web
page that's not on my server. I've been trying to find a way to read the
source code of this page into a variable so that I can parse through it for
the number. Does anyone have any suggestions (it seems like I've tried
everything)?

Craig Patchett

unread,
Jul 21, 1999, 3:00:00 AM7/21/99
to
MJ <ghjk...@hotmail.com> wrote in message
news:7n5bhj$jiq$1...@mailint03.im.hou.compaq.com...

You're kidding, right? Create a URL (java.net.URL), call openConnection() to get
the a URLConnection object, then call getContent() on the URLConnection. This
method returns an object containing the contents of the URL, and in the case of
a URL to an HTML page should return a String. Hence:

URL myURL = new URL( http://www.wherever.com/whatever.html );
URLConnection myConnection = myURL.openConnection();
String myContent = (String) ( myConnection.getContent() );

Craig

******************************************

Craig Patchett <cr...@patchett.com>
The CGI/Perl Cookbook: http://cgi-perl.com

love \luv\ (v): See John 3:16

MJ

unread,
Jul 22, 1999, 3:00:00 AM7/22/99
to
>You're kidding, right? Create a URL (java.net.URL), call openConnection()
to get
>the a URLConnection object, then call getContent() on the URLConnection.
This
>method returns an object containing the contents of the URL, and in the
case of
>a URL to an HTML page should return a String. Hence:
>
>URL myURL = new URL( http://www.wherever.com/whatever.html );
>URLConnection myConnection = myURL.openConnection();
>String myContent = (String) ( myConnection.getContent() );
>

That last line gives me a java.net.UnknownHostException for whatever URL I
use. In fact, any method of URLConnection that I try to use (getContent(),
getInputStream(), etc.) gives me that exception. Must be some setting
somewhere that I'm missing that's causing all these problems.

Dante

unread,
Jul 27, 1999, 3:00:00 AM7/27/99
to MJ
MJ,
the exception is throw by the method connect() which is invoked implicit by
getContent() if it was not done before.

I recommend you improve your exceptionhandler to give you back the hostname it
tries to resolve.
From the Spec:
"Thrown to indicate that the IP address of a host could not be determined." and

"UnknownHostException
public UnknownHostException(String host)
Constructs a new UnknownHostException with the specified detail message.
Parameters: host - the detail message."

It seems to be a network problem. Have you tried to set the proxy (if you are
behind a firewall), or if not to simply "ping" from your OS.
Also, try to use java.net.InetAddress to determine if and how the connection
can be made.

Regards
Dante

0 new messages