If you are creating an application that requires you to fetch the search results for a particular term from Wikipedia, what approach would you use?
Maybe you would use the requests
module or BeautifulSoup.
However, getting the desired data in the proper format could be a tedious job.
The Wikipedia
package can help you fetch the search results from Wikipedia with just one line of code. Before moving on, let’s first install the package by running the following command:
pip install wikipedia
Let’s now take a look at the function parameters.
wikipedia.search()
wikipedia.search()
accepts the following parameters:
query
: This is the term that you want to search.
results
: This is an optional parameter that specifies how many results you want for the query.
It accepts an integer value. The default value of this parameter is .
suggestion
: This is also an optional parameter that accepts boolean values. If True
, it will return suggestions based on your query
. The default value of this parameter is False.
The search()
function returns a list of available terms on Wikipedia for your query
.
Let’s take a look at the code:
import wikipedia as wpquery = "Python"print(wp.search(query, results = 5))
Explanation:
search()
function and pass the required parameters.query
.