Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this assignment you program a ( console ) Python program which sends search requests to Google and which displays the results of those requests

In this assignment you program a (console) Python program which sends search requests to Google and which displays the results of those requests as well as the returned HTTP response status and headers.
Preliminaries
Acquiring Access to Google Custom Search
A simple Google search typically issued through a web browser uses the following URL (example: search for 'dandelion'):
https://www.google.com/search?q=dandelion
where:
q=dandelion specifies the search query.
This type of search, however, returns HTML (to see the HTML returned by the Web server, view the 'page source' in your browser), and since HTML is not a good format for machines to consume, Google also exposes a so-called custom search JSON service which accepts standard (HTTP GET) search queries and which returns the results as JSON (example: search for 'dandelion'):
https://customsearch.googleapis.com/customsearch/v1?key=12345&cx=67890&q=dandelion
where:
key=12345 specifies a user-specific search API 'key'. (must be requested from Google)
cx=67890 specifies a user-specific custom search engine ID.(must be requested from Google)
q=dandelion specifies the search query.
Note: The two bullet items below contain links for requesting an API key and a search engine ID from Google (both free of charge). Since OSU has (very!!) recently changed its relationship with Google, you cannot use your ONID login for requesting them. Instead, use your private Google (gmail) account. If you do not (yet) have such an account, get yourself one.
Link for requesting a search API key from Google (store the key in a safe place)
Link for requesting a search engine ID from Google (store the ID in a safe place)
The API key and search engine ID (which are user specific) allow for 100 free-of-charge searches per day.
Reading Search Results
Upon a successful search, Google returns a JSON data structure containing, among lots of other things, up to 10 search results (subsequent results can be requested, but each such request counts against the quotum of 100/day. For this assignment we will only use those first 10 search results returned).
The part of the search results that we are interested in are stored in a JSON list called items (We strongly recommend that you first do a custom search using your browser, so that you can see and study the returned results).
Requirements
Since both the Google API key and the Google search engine ID are user-specific, we do not(!!!) want to store/hardwire them in our program (if we would do that, then everyone who would have our program could use our individual key and search engine ID). Instead, we will store them in a file and have the program read them from the file.
The (JSON) format of the file must be as follows:
{
"key" : "12345",
"search_engine_id" : "67890"
}
where 12345 and 67890 must be replaced with the API key and the search engine ID respectively.
IMPORTANT: note that the content of the file represents a JSON structure!!! (Again, refer to the PythonJSON lab for how to extract data from JSON structures with Python.)
In order to provide some flexibility in the naming and location of the file, we will not hardwire the file name and file location in the program, but instead pass it as a parameter on the command-line when running the program. For instance, if the program is called google_search.py, and the file with the key and search engine ID is called key.json and is located in the folder c:\temp, we will call the program as follows:
python google_search.py c:\temp\key.json
(Refer to the PythonRefresher lab on how to read command-line arguments.)
The program must prompt the user for a search term and print out the results of the search as follows:
First: HTTP response status code
Second: HTTP response headers
Third: For each of the returned items: title and link printed as follows:
title ----- link
The program keeps prompting the user for search terms until the user supplies the search term stop.
The following is an example session of the program running:

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Seven NoSQL Databases In A Week Get Up And Running With The Fundamentals And Functionalities Of Seven Of The Most Popular NoSQL Databases

Authors: Aaron Ploetz ,Devram Kandhare ,Sudarshan Kadambi ,Xun Wu

1st Edition

1787288862, 978-1787288867

More Books

Students also viewed these Databases questions

Question

Explain the factors that determine the degree of decentralisation

Answered: 1 week ago

Question

What Is acidity?

Answered: 1 week ago

Question

Explain the principles of delegation

Answered: 1 week ago

Question

State the importance of motivation

Answered: 1 week ago

Question

Discuss the various steps involved in the process of planning

Answered: 1 week ago