filmov
tv
Wikipedia API in Python

Показать описание
In this video, I’ll show you how we can implement Wikipedia API in Python to fetch information from a Wikipedia article. Let’s see how to do it-
First we have to install Wikipedia. To install it, open your command prompt or terminal and type this command-
"pip install wikipedia"
That’s all we have to do. Now we can fetch the data from Wikipedia very easily –
To get the summary of an article using Wikipedia API-
import wikipedia
output- it will fetch the summary of google from wikipedia and print it on the screen.
To get a given number of sentences from the summary of an article using Wikipedia API-
import wikipedia
output - Google LLC is an American multinational technology company that specializes in Internet-related services and products, which include online advertising technologies, search engine, cloud computing, software, and hardware.
same way you can pass any number as a parameter to get the number of sentences you want.
To change the language of the article using Wikipedia API -
import wikipedia
output – Google (prononcé [ˈguːgəl]) est une entreprise américaine de services technologiques fondée en 1998 dans la Silicon Valley, en Californie, par Larry Page et Sergueï Brin, créateurs du moteur de recherche Google.
Here fr stands for French. You can use any other code instead of fr to get the information in other language. But make sure that the Wikipedia should have that article in the language you want.
To search to get the Titles of the artcles-
import wikipedia
output - ['Google', 'Google+', 'Google Maps', 'Google Search', 'Google Translate', 'Google Chrome', '.google', 'Google Earth', 'Gmail', 'Google Scholar']
the method search() will return a list which consist of all the article’s titles that we can open.
To get the URL of the article-
import wikipedia
To get the Title of the article-
import wikipedia
output- Google
To get complete article-
import wikipedia
output- complete article from starting to end will be printed on the screen
To get the images included in article-
import wikipedia
So it will return us the URL of the particular image present at index 0. To fetch another image use 1, 2, 3 . . . . . according to images present in the article.
But if you want image to be downloaded into your local directory instead of printing the result then we can use urllib. Here’s the program which will help you to download an image from the link.
import wikipedia
import urllib
import wikipedia
If you’ve any problem or suggestion related with this article then please comment below.
First we have to install Wikipedia. To install it, open your command prompt or terminal and type this command-
"pip install wikipedia"
That’s all we have to do. Now we can fetch the data from Wikipedia very easily –
To get the summary of an article using Wikipedia API-
import wikipedia
output- it will fetch the summary of google from wikipedia and print it on the screen.
To get a given number of sentences from the summary of an article using Wikipedia API-
import wikipedia
output - Google LLC is an American multinational technology company that specializes in Internet-related services and products, which include online advertising technologies, search engine, cloud computing, software, and hardware.
same way you can pass any number as a parameter to get the number of sentences you want.
To change the language of the article using Wikipedia API -
import wikipedia
output – Google (prononcé [ˈguːgəl]) est une entreprise américaine de services technologiques fondée en 1998 dans la Silicon Valley, en Californie, par Larry Page et Sergueï Brin, créateurs du moteur de recherche Google.
Here fr stands for French. You can use any other code instead of fr to get the information in other language. But make sure that the Wikipedia should have that article in the language you want.
To search to get the Titles of the artcles-
import wikipedia
output - ['Google', 'Google+', 'Google Maps', 'Google Search', 'Google Translate', 'Google Chrome', '.google', 'Google Earth', 'Gmail', 'Google Scholar']
the method search() will return a list which consist of all the article’s titles that we can open.
To get the URL of the article-
import wikipedia
To get the Title of the article-
import wikipedia
output- Google
To get complete article-
import wikipedia
output- complete article from starting to end will be printed on the screen
To get the images included in article-
import wikipedia
So it will return us the URL of the particular image present at index 0. To fetch another image use 1, 2, 3 . . . . . according to images present in the article.
But if you want image to be downloaded into your local directory instead of printing the result then we can use urllib. Here’s the program which will help you to download an image from the link.
import wikipedia
import urllib
import wikipedia
If you’ve any problem or suggestion related with this article then please comment below.
Комментарии