是否可以通过Google自定义搜索API获取网站的完整标题?

问题描述 投票:0回答:1

我正在制作一个使用Google搜索api的网络应用程序,但是我的问题是,它仅从网站标题中获得前10个单词。有什么办法可以扩展以获得整个标题,或者更好的选择是获取网页的内容并仅解析<title>标签的内容?我正在使用纯JavaScript。谢谢!

javascript json get google-search-api page-title
1个回答
0
投票

您将需要对URL进行请求,获取HTML,然后从HTML中解析出标题。

function httpGet(theUrl)
{
    var xmlHttp = new XMLHttpRequest();
    xmlHttp.open( "GET", theUrl, false ); // false for synchronous request
    xmlHttp.send( null );
    return xmlHttp.responseText;
}

httpGet('http://some/url', function(response) {
    // parse the title tag here
});
© www.soinside.com 2019 - 2024. All rights reserved.