• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

How can I parse a webpage for information?

 
Ranch Hand
Posts: 184
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to parse a webpage ( http://setiathome.ssl.berkeley.edu/fcgi-bin/fcgi?email=CompiledMonkey@attbi.com&cmd=user_stats_new ) in my servlet to return how many units I've completed. I'd also like to do this for other websites (weather and such). How should I go about doing this? Thanks for any advice.
[ October 20, 2002: Message edited by: James Davis ]
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was going to reply "try URLConnection", but then I decided to try it myself (for the first time ever), and it is a bit harder than I thought. Finally found the code on java.sun.com here:

http://java.sun.com/docs/books/tutorial/networking/urls/readingURL.html

I've modified that code slightly because of firewalls and I've used a StringBuffer so that it can all be parsed later. You might modify your code to only readLine() until you find the data you're looking for, and then exit that loop and close the connection (no need to read in the entire page if you only want something appearing in the first 20% of the page).


[ October 21, 2002: Message edited by: Mike Curwen ]
 
Chris Stewart
Ranch Hand
Posts: 184
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks! It works great.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic