• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

parsing inputStream

 
kwame Iwegbue
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm writing a small program to that connects to a URL and reads it

e.g

//...

URL yahoo new URL("http://yahoo.com/");
URLConenection yc = yahoo.openConnection();
BufferedReader in new BufferedReader(new InputStreamReader(yc.getInputStream()));

//...more code to readLine and then print etc

can someone please tell me of a method in java.net or otherwise, that could be used to get a certain type of information from an input stream say a certain link or a some known string, instead of just the whole page!!!

thanks
[ October 11, 2005: Message edited by: kwame Iwegbue ]
 
Norm Radder
Bartender
Posts: 1363
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depends on what the "certain type of information" is and what the contents of the input stream is. For example if the content of the stream is a gif file, what would you want to get?
Please describe the input data?
 
kwame Iwegbue
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
say i want to get only a particular string of text from the page, or only a particular link which is already known to me, so that i can print only that string of text or maybe even follow only that link from the page...

[ October 11, 2005: Message edited by: kwame Iwegbue ]
[ October 11, 2005: Message edited by: kwame Iwegbue ]
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depending on the complexity of the parsing you want to do, you can use IntputStreamTokenizer, classes in java.util.regex, or a full blown parser such as javacc. No matter which of these you choose, you will ened up reading the complete content of the InputStream (or close to it).

Layne
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should probably google for an open source Java html parser...
 
kwame Iwegbue
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your suggestions. They were quite useful. Does anyone know where to find tutorials on 'parsing HTML" I've done a google search, but it seems only one article at java.sun came close to what I need. it was addressing Swing HTML parser. but can I find more articles? specifically, I'm trying to parse out text from a html file
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15495
43
Android IntelliJ IDE Java Scala Spring
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic