views:

44

answers:

4

how can i get links in a web page without loading it? (basically what i want is this. a user enters a URL and i want to load all the available links inside that URL.) can you please tell me a way to achieve this

A: 

You'll have to load the page on your server and then find the links, preferably by loading up the document in an HTML/XML parser and traversing that DOM. The server could then send the links back to the client.

You can't do it on the client because the browser won't let your Javascript code look at the contents of the page from a different domain.

Pointy
can you please give me code example or any link to a resource where i can study a bit about it
netha
It completely depends on what sort of server-side environment you've got. There are many, many possibilities.
Pointy
A: 

If you want the content of a page you'll have to load it. But what you can do is loading it in memory and parse it to get all the <a> tags and their content.

You'll be able to parse this XML with tools like JDom or Sax if you're working with java (as your tag says) or with simple DOM tools with javascript.


Resources :

On the same topic :

Colin Hebert
Bearing in mind that a lot of websites won't parse as 'valid' XML...
Paddy
@Paddy, you're right, and in this case the best thing to do is looking right to the `<a` tags manually.
Colin Hebert
A: 

Just open an URLConnection, gets the page and parse it.

Spilarix
+3  A: 

Here is code

org.life.java
@Netha, can you post whole stacktrace,
org.life.java