0

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

目前,我正在使用 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 上编入索引的网页,这些网页是提交 URL 时的第一个结果。

谁能做得更好?

4

1 回答 1

4

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

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

在他们的控制台中自己尝试一下。

于 2012-08-07T07:53:13.533 回答