File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

View HTML source using Java?

 
Paul Smith
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello People,

Can you guide me as to what methods I'll need (it's doing my head in for some reason) to use in other to view an HTML source code.

NB: As I am learning PLEASE don't just give me the code on a plate. Advise, guide, direction etc, will be most appreciated.

Thanks a million.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

What's the context? A user with a foo.html file on their hard disk? A web browser?

When you say "view HTML source code" that generally means to view the actual contents of the HTML as plain text; but I should make sure you don't mean render the HTML, as a web browser would.

So explain a bit more of what you want to do, and I'm sure we'll be able to help you.
 
James Carman
Ranch Hand
Posts: 580
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Smith:
Hello People,

Can you guide me as to what methods I'll need (it's doing my head in for some reason) to use in other to view an HTML source code.

NB: As I am learning PLEASE don't just give me the code on a plate. Advise, guide, direction etc, will be most appreciated.

Thanks a million.


As an aside, I would like to applaud you for taking the initiative to learn this for yourself rather than asking others to "give you the code on a plate." There's nothing wrong with asking for a little guidance now and then. If you take the time to answer Mr. Friedman-Hill's (pay attention to this guy. I've read his book on JESS and he's very sharp and very informative) question(s), I'm sure one of us can help direct you on your way.
 
Paul Smith
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys (Ernest Friedman-Hill & James Carman),

What I mean is that when a user types in a wb address(from command promt maybe), the program should return the HTML source code for that website.

So far I can mimic the unix 'nslookup' program ie: return the IP or Host name of hostnames/IPs entered by the user. I think it might be similar, maybe that's where I'm goin wrong.

I am listening for user inputs using:

String readFromKeyboard;

BufferedReader connectsKeyboard = new BufferedReader(new InputStreamReader(System.in));
readFromKeyboard = connectsKeyboard.readLine();

I have instantiated URL:

URL aSite = new URL (readFromKeyboard);
System.out.println("I can't seem to find this magic method " + aSite.getFile());

At this point im just picking out methods all over the place. getFile() is just one of many I've tried...getContent() & so on.

I hope I'm a bit clearer now - thanks again people.
 
James Carman
Ranch Hand
Posts: 580
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
More specifically, check out its subclass HttpURLConnection. When you ask for a connection from your URL, you'll have to cast it to an HttpURLConnection. That class has methods specific to the HTTP protocol on it that you might find useful.
 
Paul Smith
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have sorted out my program - it does what I want...

It's all in the API...I just have to understand how to use the API properly.

Thanks to you all..

PS: It was all mainly to do with BufferedReader, InputStreamReader & getInputStream.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic