views:

92

answers:

2

Hi there,

I browsed through SO, but what I found were examples "how to manipulate a piece of html". But in my case, I want to fetch a HTML file by a given URL and just parse the websites title not the whole file.

Is there any way to do this with jQuery or any jQuery like framework?

regards,

A: 

2911930 looks to have the answer

$.get("yoururl", function(response){
    var theTitle = (/<title>(.*?)<\/title>/m).exec(response)[1];
    alert(theTitle);
});

edit As pointed out by the commenters, you'll be restricted by SOP to pages only within your domain. And, generally, parsing HTML with regular expressions is a Bad Thing, but not too bad in this case.

Dan F
This will not work unless the url is on the same domain as the calling page
redsquare
You're supposing OP only requests urls from his own domain. This won't work as soon as a foreign domain comes into play. Furthermore, parsing html with regular expressions is a bad idea in general.
jAndy
+6  A: 

The only way is to use a server side proxy which makes the web request and parses out the title which you can return to your page.

See a php example here

For python try the urllib

redsquare
Right +1. Being able to do this with the browser only would open the door to many security issues.
Luca Matteis
Any Python / AppEngine example out there? =)
daemonfire300
http://docs.python.org/library/urllib.html
redsquare