Disable Highlighting in Google API WebSearch Result Title

微笑、不失礼 提交于 2020-01-16 18:17:09

问题


I've been using Google Web Search API but the searched keyword is coming highlighted - with b tag- in the title property of the return object.

I thought webSearchControl.setNoHtmlGeneration(); could work but didn't change anything.

I know how to deal with other ways but is there any ways Google API provides to avoid any html thing in the response?

Thanks.

By the way let me paste my code here for further info :

google.load("search", "1", { "nocss": true });

function OnLoad() {
    // Create a search control
    var webSearchControl = new google.search.WebSearch();
    webSearchControl.setResultSetSize(google.search.Search.LARGE_RESULTSET);
    webSearchControl.setNoHtmlGeneration();
    webSearchControl.setSearchCompleteCallback(this, OnCompleted, [webSearchControl]);
    webSearchControl.execute("programming");
    setInterval(function () {
        webSearchControl.execute("Programming");
    }, 3000);

}

function OnCompleted(webSearchControl) {
    var results = webSearchControl.results;
    $("#googleSearch").html($("#googleSearch").html() + '<br/><a href=' + results[0].url + ' target="blank">' + results[0].title + '</a>');
}

google.setOnLoadCallback(OnLoad);

回答1:


I've just found the solution:

It should be something like this :

$("#googleSearch").html($("#googleSearch").html() + '<br/><a href=' + results[0].url + ' target="blank">' + results[0].titleNoFormatting + '</a>');
}

So basically .titleNoFormatting solves the problem here.



来源:https://stackoverflow.com/questions/2384719/disable-highlighting-in-google-api-websearch-result-title

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!