Send Close Add comments: (status displays here)
Got it!  This site uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website.nbsp; Note: This appears on each machine/browser from which this site is accessed.
Auto-complete search terms


1. Auto-complete search terms
The Google API (and others) can be used to get suggestions to auto-complete a typed query (in progress).

It is intended for JavaScript usage from a web page but can be automated using Python.

2. Browser
Try the following URL in your browser.
http://suggestqueries.google.com/complete/search?client=firefox&q=corovirus

A browser such as Chrome or Firefox will allow the text to be saved as text - but it is a JSON list.

3. Text
Here is the returned JSON text, formatted to be easier to read.
["corovirus",    [    "coronavirus",    "coronavirus map",    "coronavirus us",    "coronavirus in usa",    "coronavirus update",    "coronavirus tips",    "coronavirus vaccine",    "coronavirus china",    "coronavirus symptoms",    "coronavirus italy"    ] ]


4. Python
This manual operation can be automated using, say, Python.

The code shows how a date and time stamp might be created in order to save the results on a periodic basis to a file in a given folder.

5. Python example
Here is the Python code.

Here is the output of the Python code.


6. Notes
In the result, the first element in the list is the search term provided. The second item is a list of suggestions which, of course, will always start with the search term provided since the suggestions are intended to help complete what is typed for a search (of the Google site).

7. Saving results
One way to save results as JSON (or other format) is as follows.

8. Research
A few years ago, I set up a Raspberry Pi to periodically get the suggested search term completion suggestions for a set of search terms. The idea was to wake up every few hours (say 1 to 24 times a day, using a cron job), and check the suggestions.

The analysis then was to determine, over time, what search terms and orderings had changed.

9. End of page