2

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,

Dan F
  • 11,958
  • 3
  • 48
  • 72
Julius F
  • 3,434
  • 4
  • 29
  • 44

2 Answers2

6

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
  • 78,161
  • 20
  • 151
  • 159
-1

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.

Community
  • 1
  • 1
Dan F
  • 11,958
  • 3
  • 48
  • 72
  • 2
    This will not work unless the url is on the same domain as the calling page – redsquare Jul 04 '10 at 10:31
  • 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 Jul 04 '10 at 10:32