【问题标题】:How to display google results on same page without sending form to google itself如何在同一页面上显示谷歌结果而不向谷歌本身发送表单
【发布时间】:2020-02-04 20:20:58
【问题描述】:

<!DOCTYPE html>
<head>
</head>
<body>
<form action="https://www.google.com/search" method="GET">
<input type="text" name="q" placeholder="MySearch">
<input type="submit" value="MySearch">
</form>
</body>
</html>

这会将页面发送到谷歌。我想留在我的页面上,只显示来自 google 的列表结果。

【问题讨论】:

标签: jquery html search


【解决方案1】:

可以使用 Google 搜索 API,您可以在下面找到代码 sn-p 并在此处了解更多有关其工作原理的信息 https://developers.google.com/custom-search/docs/tutorial/introduction

祝你好运

function getGoogleSearchResults(q) {

// Get the API key from Google's developer console
// Get the CSE ID from google.com/cse

var api = "https://www.googleapis.com/customsearch/v1?key=" +
    KEY + "&cx=" + CSE + "&q=" + encodeURIComponent(q);

try {

    var response = UrlFetchApp.fetch(api, {
        muteHttpExceptions: true
    });

    if (response.getResponseCode() == 200) {

        var content = JSON.parse(response);

        // Did the search return any results?
        if (content.searchInformation.totalResults > 0) {

            var count = content.items.length;

            for (var i = 0; i < count; i++) {

                // Save the page title, description and hyperlink
                Logger.log(content.items[i].title);
                Logger.log(content.items[i].snippet);
                Logger.log(content.items[i].link);
            }
        }
    }
} catch (f) {
    Logger.log(f.toString());
}

}

【讨论】:

  • 你能举一个使用这个函数的例子吗?
猜你喜欢
  • 1970-01-01
  • 2021-04-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-20
  • 1970-01-01
  • 2016-06-12
相关资源
最近更新 更多