Reputation: 733
I want to be able to type in a web address in my java application and view the html behind that web page. I am lost. How do I start?
The main question is how do I link to the html behind a webpage?
Any meta information would help. I haven't done any web stuff before.
Thanks guys, thats a huge help!
Upvotes: 0
Views: 820
Reputation: 9217
The main question is how do I link to the html behind a webpage?
There is no difference in linking to a website or the html behind a website. It always points to the HTML source code.
What differs is what is done with it. A webbrowser will interpret and format it and display it to you as a styled website. You can still check its source in your browser though. A Text editor will only display the HTML markup to you.
Upvotes: 2
Reputation: 49187
The html behind the page you are referring to is in all essence the page. When the browser fetches the page it interprets it and renders it in a user friendly way.
When you do it programmatically there is no rendering. Hence the content of the page is the html. I would recommend using Apache HttpClient to perform HTTP requests, or the URL
method nicely described by @aioobe.
Upvotes: 2
Reputation: 420951
If you're just interested in the source of the page on a specific URL, you can use the URL
class and the openConnection
/ getInputStream
methods:
This sample program prints the content of http://www.google.com
:
import java.io.IOException;
import java.net.URL;
import java.util.Scanner;
public class Test {
public static void main(String[] args) throws IOException {
URL url = new URL("http://www.google.com");
Scanner s = new Scanner(url.openConnection().getInputStream());
while (s.hasNextLine())
System.out.println(s.nextLine());
}
}
Upvotes: 2