获取客户端的外部页面标题

时间:2012-08-07 07:30:50

标签: javascript jquery html5

我的目标是在我的页面上打印外部页面的标题,而无需在服务器端加载前者。

目前,我正在使用jQuery和Google的搜索API。看看以下解决方案的hackyness:

//Use google search api to get page title for link
var url = "http://ajax.googleapis.com/ajax/services/search/web?q=" + **URL** + "&v=1.0&callback=?"
//Set URL for link
$("#link").attr("href", content);
//Execute google api JSON query
$.getJSON(url, function (data) {
  //Insert the unformatted title of the first result into the page
  $("#title").append(data.responseData.results[0].titleNoFormatting);
});

^效果很好,但仅适用于在Google上编制索引的网页,这是提交网址时的第一个结果。

谁能做得更好?

1 个答案:

答案 0 :(得分:4)

尝试YQL,获取标题的示例查询:

select * from html where url="http://cute-kittens.tumblr.com/" and xpath='//head/title'

亲自尝试console

相关问题