<!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。我想停留在我的页面上,只显示来自Google的列表结果。
可以使用Google Search API,您可以在下面找到代码段,并在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());
}
}