We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 8 months ago.
The community reviewed whether to reopen this question 8 months ago and left it closed:
Original close reason(s) were not resolved
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(6)
新网址为:
http://suggestqueries.google.com/complete/ search?client=firefox&q=YOURQUERY
客户端部分是必需的;我没有测试其他客户端。
[编辑]
如果您想要回调,请使用以下命令:
http: //suggestqueries.google.com/complete/search?client=chrome&q=YOURQUERY&callback=callback
@Quandary 发现;该回调不适用于客户端“firefox”。
[EDIT2]
正如 @ user2067021 所示,此 api 将在 2015 年 10 月 8 日停止工作:自动完成 API 更新
The new url is:
http://suggestqueries.google.com/complete/search?client=firefox&q=YOURQUERY
the client part is required; I did't test other clients.
[EDIT]
If you want the callback use this:
http://suggestqueries.google.com/complete/search?client=chrome&q=YOURQUERY&callback=callback
As @Quandary found out; the callback does not work with client "firefox".
[EDIT2]
As indicated by @ user2067021 this api will stop working as of 10-08-2015: Update on the Autocomplete API
上面提到的大多数方法都适合我,具体来说以下方法符合我的目的。
作为网络编程的新手,我不太了解“回调”功能和查询返回的文件的格式。我对 AJAX 和 JSON 知之甚少。
有人可以提供有关查询返回的文件格式的更多详细信息吗?
谢谢。
Most of the above mentioned methods works for me, specifically the following serves my purpose.
Being a newbie in web programming, I'm not much aware of the "Callback" functionality and the format of the file returned by query. I'm little aware of AJAX and JSON.
Could someone provide more details about the format of file returned by the query.
Thanks.
首先,转到谷歌,单击设置(右下角),将搜索设置更改为“从不显示即时结果”。这样,您将获得定期自动完成而不是整页即时结果。
保存设置后,返回打开浏览器的开发人员工具并转到“网络”选项卡。如果您使用的是 Firefox,则可能需要
在搜索框中重新输入一个字母。“网络”中应该会出现一个新行。您刚刚打开的窗口正在显示。自动完成数据的来源。它应该看起来像这样:
”部分后面注意到您的搜索词。
您会在“Add
&callback=myAmazingFunction 您可以将 myAmazingFunction 替换为您想要处理数据的函数的名称。
是显示搜索词“a”的自动完成数据所需的代码示例。
下面 如果您知道如何获取数据,下一步就是自动更改最后一个脚本(带有自动完成 url 的脚本)。基本过程是:每次用户在搜索框 (onkeyup) 中键入内容时,替换 url 中的搜索词 (q=whatever),然后将带有该 url 的脚本附加到正文。删除之前的脚本,以免正文变得混乱。
有关详细信息,请参阅 http://simplestepscode.com/autocomplete-data-tutorial/
First, go to google, click Settings (bottom right corner), change Search Settings to "never show instant results. That way, you'll get regular autocomplete instead of a full page of instant results.
After your settings are saved, go back to the Google main home page. Open your browser's developer tools and go to the Network tab. If you're in Firefox, you might have to reload the page.
Type a letter in the search box. A new line should appear in the Network window you just opened. That line is showing where the autocomplete data came from. Copy that url. It should look something like this:
You'll notice your search term right after the part that says
q=
.Add
&callback=myAmazingFunction
to the end of the url. You may replace myAmazingFunction with whatever you want to name your function that will handle the data.Here's an example of the code required to show the autocomplete data for the search term "a".
Now that you know how to get the data, the next step is to automatically change that last script (the one with the autocomplete url). The basic procedure is: each time the user types something in the search box (onkeyup) replace the search term (q=whatever) in the url, and then append to the body a script with that url. Remove the previous script so that the body doesn't get cluttered.
For more info, see http://simplestepscode.com/autocomplete-data-tutorial/
您好,我不知道这个答案是否与您相关,但谷歌通过以下 get 请求返回 JSON 数据(尽管这不是官方 API,但许多工具栏正在使用此 API,因此谷歌没有理由停止它):
Hi I don't know if this answer is relevant for you anymore or not but google returns JSON data through following get request (although this isn't an official API but many toolbars are using this API so there's no reason why google might discontinue it):
您应该使用 AutocompleteService 并将该文本框值传递到
service.getPlacePredictions
函数中。它在回调函数中发送数据。基础:https://developers.google。 com/maps/documentation/javascript/reference/places-autocomplete-service#AutocompleteService.getPlacePredictions
示例:https://dzone.com/articles/implement-and-optimize-使用-google-pl 自动完成
You should use AutocompleteService and pass that text box value into the
service.getPlacePredictions
function. It send the data in callback function.Base: https://developers.google.com/maps/documentation/javascript/reference/places-autocomplete-service#AutocompleteService.getPlacePredictions
example: https://dzone.com/articles/implement-and-optimize-autocomplete-with-google-pl
您可以使用关键字 Quill,它提供 Google 自动完成 API。免费获取 API 密钥并向端点发出请求。
用于查找短语“空气炸锅”的自动完成关键字的 JS 示例如下:
You can use Keyword Quill, which offers a Google autocomplete API. Get an API key for free and make a request to the endpoint.
A JS example for finding autocompleted keywords for the phrase "air fryers" would be: