Python Wikipedia Module with Examples

Wikipedia Module:

Python’s Wikipedia module can be used to get a large amount of information from the well-known Wikipedia website.

We will begin by including the Wikipedia module in our system. If the importing command fails to work. Make sure you use the pip command to install the module.

Installation of wikipedia module:

pip install wikipedia

Output:

Collecting wikipedia Downloading wikipedia-1.4.0.tar.gz (27 kB) Requirement 
already satisfied: beautifulsoup4 in /usr/local/lib/python3.7/dist-packages 
(from wikipedia) (4.6.3) Requirement already satisfied: requests<3.0.0,>=2.0.0 
in /usr/local/lib/python3.7/dist-packages (from wikipedia) (2.23.0) Requirement 
already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7/dist-packages 
(from requests<3.0.0,>=2.0.0->wikipedia) (2.10) Requirement already satisfied: 
certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests<3.0
.0,>=2.0.0->wikipedia) (2021.10.8) Requirement already satisfied: chardet<4,>=3
.0.2 in /usr/local/lib/python3.7/dist-packages (from requests<3.0.0,>=2.0.0->
wikipedia) (3.0.4) Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,
<1.26,>=1.21.1 in /usr/local/lib/python3.7/dist-packages (from requests<3.0.0,>
=2.0.0->wikipedia) (1.24.3) Building wheels for collected packages: wikipedia 
Building wheel for wikipedia (setup.py) ... done Created wheel for wikipedia: 
filename=wikipedia-1.4.0-py3-none-any.whl size=11696 sha256=77f5cc37acc194cd3b
7e74d9980194a3ef1a991797e43b89a69bc102dedafc4d Stored in directory: /root/.
cache/pip/wheels/15/93/6d/5b2c68b8a64c7a7a04947b4ed6d89fb557dcc6bc27d1d7f3ba 
Successfully built wikipedia Installing collected packages: wikipedia 
Successfully installed wikipedia-1.4.0

How to get the Data from the Wikipedia module?

To get Random Pages:

Choosing appropriate titles to search for might be a difficult process at times. Using the random method, one can obtain random titles.

If we require more than one random title, we can pass the number of pages as a parameter to the method. A list of titles is returned by the function.

# Import wikipedia module using the import keyword.
import wikipedia 
# Pass the number of pages as an argument to the random() function to get some 
# random titles and print it
print(wikipedia.random(pages=8))

Output:

['Gabriel P 6', 'Ambulyx charlesi', "Shooting at the 2014 Asian Games –
 Women's 10 metre air pistol team", 'Favolaschia', 'Akheem Gauntlett', 
'Jhorahat', 'Pavan Deshpande', 'Valerio Baldassari']

To get the summary:

Any tittle can be summarised using the summary method.

The summary method accepts a string as an argument that defines the title to search for. It returns a number of sentences for the specified title.

We can also add the number of sentences required as a parameter to limit the amount of stored data.

Approach:

  • Import wikipedia module using the import keyword.
  • Pass some random string, no of sentences as the argument to the summary() function.
  • Store it in a variable.
  • Print the above result.
  • The Exit of the Program.

Below is the implementation:

# Import wikipedia module using the import keyword.
import wikipedia
# Pass some random string, no of sentences as the argument to the summary() function
# Store it in a variable
sumry = wikipedia.summary('Ms. Dhoni-cricketer', sentences=40)
# Print the above result.
print(sumry)

Output:

M.S. Dhoni: The Untold Story is a 2016 Indian Hindi-language biographical sports
drama film written and directed by Neeraj Pandey. It is based on the life of
 former Test, ODI and T20I captain of the Indian national cricket team, Mahendra Singh Dhoni. The film stars the late Sushant Singh Rajput as Dhoni, along with Disha Patani, Kiara Advani, and Anupam Kher. The film chronicles the life of Dhoni from a young age through a series of life events. The idea of the biopic was put forward by Dhoni's manager, Arun Pandey, after encountering an incident at an airport after the 2011 Cricket World Cup Final. Development began two years later, with the consent of Dhoni. Neeraj Pandey was later approached to helm the film while he was working on Baby. Pandey recruited a number of people for researching into Dhoni's background and his life events. Dhoni eventually became a consultant on the film. The film was released on 30 September 2016 by Fox Star Studios and received the widest release ever for a Bollywood film across 61 countries.

To get the entire Wikipedia Page:

The page() function takes the title of the page as an argument and returns the whole Wikipedia Page.

The function returns a page object for the specified title. We can extract further information from the page object that was created.

Approach:

  • Import wikipedia module using the import keyword.
  • Pass some random title as an argument to the page() function to get the whole Wikipedia Page.
  • Store it in a variable.
  • Print the above-obtained page object.
  • Print the title of the given page using the original_title() function.
  • Print the categories of the given page using the categories() function.
  • Print the contents of the given page using the content() function.
  • The Exit of the Program.

Below is the implementation:

# Import wikipedia module using the import keyword.
import wikipedia
# Pass some random title as an argument to the page() function to get the whole
# Wikipedia Page.
# Store it in a variable.
gvn_page = wikipedia.page('Ms.Dhoni')
# Print the above-obtained page object.
print(gvn_page)
# Print the title of the given page using the original_title() function.
print("The title of the given page - \n", gvn_page.original_title)
print("\n")
# Print the categories of the given page using the categories() function.
print("The categories of the given page - ", gvn_page.categories)
print("\n")
# Print the contents of the given page using the content() function.
print("The contents of the given page -", gvn_page.content)

Output:

<WikipediaPage 'MS Dhoni'>
The title of the given page - 
 MS Dhoni


The categories of the given page -  ['1981 births', 'ACC Asian XI One Day International cricketers', 'All Wikipedia articles written in Indian English', 'All accuracy disputes', 'All articles covered by WikiProject Wikify', 'All articles lacking reliable references', 'All articles that are excessively detailed', 'All articles with specifically marked weasel-worded phrases', 'All articles with style issues', 'All articles with unsourced statements', 'All articles with vague or ambiguous time', 'All pages needing cleanup', 'All pages needing factual verification', 'Articles covered by WikiProject Wikify from December 2021', 'Articles lacking reliable references from December 2021', 'Articles lacking reliable references from November 2021', 'Articles lacking reliable references from October 2021', 'Articles needing more detailed references', 'Articles needing the year an event occurred from December 2021', 'Articles that may be too long from October 2021', 'Articles with FAST identifiers', 'Articles with GND identifiers', 'Articles with ISNI identifiers', 'Articles with LCCN identifiers', 'Articles with VIAF identifiers', 'Articles with WORLDCATID identifiers', 'Articles with disputed statements from October 2021', 'Articles with multiple maintenance issues', 'Articles with short description', 'Articles with specifically marked weasel-worded phrases from December 2021', 'Articles with unsourced statements from December 2021', 'Articles with unsourced statements from February 2019', 'Bihar cricketers', 'CS1 errors: bare URL', 'CS1 errors: missing title', 'CS1 maint: numeric names: authors list', 'CS1 maint: others', 'Wikipedia indefinitely semi-protected biographies of living people', 'Wikipedia introduction cleanup from December 2021']


The contents of the given page - Mahendra Singh Dhoni (born 7 July 1981), is a former international cricketer who captained the Indian national cricket team in limited-overs formats from 2007 to 2017 and in Test cricket from 2008 to 2014. He is currently the captain of Chennai Super Kings (CSK), a franchise based team of Indian Premier League. Having won the triple ICC limited-overs tournament as captain (inaugural 2007 ICC World Twenty20, 2011 ICC Cricket World Cup and 2013 ICC Champions Trophy) and bringing Indian cricket team to number one position in ICC test rankings in 2009, Dhoni is often considered as the greatest captain of Indian cricket team. Furthermore, he led CSK to win 2010, 2011, 2018 and 2021 edition of IPL, becoming second most successful IPL captain after Rohit Sharma.
Dhoni made his ODI debut on 23 December 2004 against Bangladesh, and played his first Test a year later against Sri Lanka. In 2007, he took over the ODI captaincy from Rahul Dravid. In test cricket his captaincy record was mixed, successfully leading India to series win against New Zealand (in 2009) and the Border-Gavaskar Trophy (home series in 2010 and 2013) against Australia while losing to Sri Lanka, Australia, England, and South Africa by big margins in away conditions. He announced his retirement from Tests on 30 December 2014 and captain of limited-overs game in 2017. Virat Kohli succeeded him as captain in both cases.
Dhoni announced his retirement from international cricket on 15 August 2020.


== Early life and background ==
Dhoni was born in Ranchi, Bihar (now in Jharkhand), and he hails from a Hindu Rajput family. His paternal village Lwali is in Jainti tehsil, Lamgara block of the Almora District of Uttarakhand. Dhoni's father is Pan Singh and his mother is Devaki Devi. His parents moved from Uttarakhand to Ranchi, Bihar where his father Pan Singh worked in junior management positions in MECON. He has a sister Jayanti Gupta and an elder brother Narendra Singh Dhoni.  His uncle, Pan Singh's brother, Ganapat Singh Dhauni lives in Lwali. Dhoni's uncle and cousins spell their surname as Dhauni but Mahendra Singh spells as Dhoni.Bhojpuri language is Dhoni's mother tongue.He is a fan of Adam Gilchrist, and his childhood idol in game of cricket was his former team-mate and former cricketer, Sachin Tendulkar. 


== Early career ==


=== Junior cricket in Bihar ===
In 1998, Dhoni was selected by Deval Sahay to play for the Central Coal Fields Limited (CCL) team. Till 1998 Dhoni, who was in class 12th in school, had played only school cricket and club cricket and no professional cricket. One of the famous episodes, when Dhoni used to play for CCL, was when Deval Sahay used to gift him Rs 50 for each six that he hit in Sheesh Mahal tournament cricket matches. Playing for CCL, he got a chance to bat up the order. He grabbed the opportunity and scored centuries and helped CCL move to the A division. tches, as East Zone lost all four matches and finished last in the tournament.


=== Bihar cricket team ===

Dhoni made his Ranji Trophy debut for Bihar in the 1999–2000 season, as an eighteen-year-old. He made a half century in his debut match scoring 68* in the second innings against Assam cricket team. Dhoni finished the season with 283 runs in 5 matches. Dhoni scored his maiden first-class century while playing for Bihar against Bengal in the 2000/01 season, this match ended as draw Apart from this century, his performance in the 2000/01 season did not include another score over fifty and in the 2001/02 season, he scored just five fifties in four Ranji matches.


=== Jharkhand cricket team ===
Dhoni's performance in the 2002–03 season included three half-centuries in the Ranji Trophy and a couple of half-centuries in the Deodhar Trophy, as he started gaining recognition for his lower-order contribution as well as hard-hitting batting style. In the 2003/04 season, Dhoni scored a century (128*) against Assam in the first match of the Ranji ODI tournament. Dhoni was part of the East Zone squad that won the Deodhar Trophy 2003–2004 season and contributed with 244 runs in 4 matches, including a century (114) against Central zone.y.


=== Start of ODI career ===
The Indian ODI team in the early 2000s saw Rahul Dravid as the wicket-keeper to ensure that the wicket-keeper spot didn't lack in batting talent. The team also saw the entry of wicket-keeper/batsmen from the junior ranks, with talents like Parthiv Patel and Dinesh Karthik (both India U-19 captains) named in the Test squads. With Dhoni making a mark in the India A squad, he was picked in the ODI squad for the Bangladesh tour in 2004/05. Dhoni did not have a great start to his ODI career, getting run out for a duck on debut. In spite of an average series against Bangladesh, Dhoni was picked for the Pakistan ODI series.


=== 2007 World Cup ===
Preparations for the 2007 Cricket World Cup improved as India recorded identical 3–1 victories over West Indies and Sri Lanka and Dhoni had averages in excess of 100 in both these series.India unexpectedly crashed out of the World Cup after losses to Bangladesh and Sri Lanka in the group stage. Dhoni was out for a duck in both these matches and scored just 29 runs in the tournament. After the loss to Bangladesh in 2007 Cricket World Cup, the house that Dhoni 

=== Rise through ranks ===
During the series between India and Australia in 2009, Dhoni hit an aggressive 124 runs in just 107 balls, in the second ODI, and a measured knock of 71 runs in 95 balls, along with Yuvraj Singh and saw India home by 6 wickets in the third ODI. Dhoni took his first and only wicket in international cricket on 30 September 2009. He bowled Travis Dowlin of the West Indies during a match in the 2009 ICC Champions Trophy.


=== 2015 World Cup ===
India's preparation, going into the tournament, looked poor as India failed badly in the Carlton Mid Triangular Series in Australia, failing to win a single match. Dhoni himself managed just 70 runs from three innings averaging 23.34.During the 2015 Cricket World Cup, Dhoni became the first Indian captain to win all group stage matches in such a tournament. India achieved wins against arch-rivals Pakistan, South Africa (whom they hadn't beaten before in a World Cup game), the UAE, West Indies, Ireland and Zimbabwe.

=== Stepping down as captain and thereafter ===
Dhoni stepped down as captain of India in the limited over formats in January 2017, just ahead of the ODI series at home against England. In the second game of the series, he scored 134 off 122 balls, that included a 256-run partnership for the fourth wicket along with Yuvraj Singh.

=== Retirement from international cricket ===
Dhoni announced his retirement from international cricket on 15 August 2020 on the day of India's 74th independence. He did so by posting a video on Instagram that contained pictures from both the best and the worst moments of his career with the song Mai Pal do Pal ka Shayar Hoon playing in the background. The video had been captioned as "Thanks a lot for ur love and support throughout.from 1929 hrs consider me as Retired".In November 2020, Dhoni was nominated for the ICC Men's ODI Cricketer of the Decade and ICC Spirit of Cricket Award of the Decade. Eventually, Dhoni was voted as winner of the ICC Spirit of Cricket Award of the Decade.


== Domestic career ==
On 23 December 2015, Delhi vs Jharkhand, in Vijay Hazare trophy Dhoni scored 70 (108) runs at 2nd quarter final at M. Chinnaswamy Stadium, Jharkhand lost that match.In 2017 Dhoni scored 129 (107) against Chhattisgarh at Eden gardens stadium in Kolkata in Vijay Hazare trophy, a one-day match tournament.He debuted in first class and List A Cricket in the season of 1999-2000.   In domestic cricket circuit he played for the teams such as Bihar, Jharkhand, 


== World Cup ==
Dhoni has captained India in two World Cups. Under his captaincy, India won the World Cup in 2011.


=== 2007 Cricket World Cup ===
Dhoni played his first ODI World Cup in 2007 in the Caribbean. 


=== 2011 Cricket World Cup ===

The bat used by Dhoni in the final match was sold for ₹72 Lac. The money goes to Sakshi Rawat Foundation, operated by Dhoni's wife Sakshi Rawat to help orphan children.


=== 2015 Cricket World Cup ===
For the 2015 World Cup held in Australia and New Zealand, Dhoni was named the captain of the 30-member squad by the BCCI in December 2014. Under his captaincy, India was able to go through to the semi-finals with ease, beating Bangladesh in the quarter-finals. 


== Indian Premier League ==

Dhoni was contracted by the Chennai Super Kings for US$1.5 million. This made him the most expensive player in the IPL for the first season auctions. Under his captaincy, Chennai Super Kings won the 2010, 2011, 2018 and the 2021 Indian Premier League titles and the 2010 and 2014 Champions League T20 titles.MS Dhoni became the first player to play 200 T20 matches for Chennai Super Kings. The former India captain is already on top of the list of most matches played in the Indian Premier League. Mahendra Singh Dhoni is also one of the only three captains to have won the Indian Premier League twice, with Chennai Super Kings.

== Playing style ==
Dhoni is a right-handed batsman and wicket-keeper. Dhoni is an unorthodox batsman in the sense that much of his batting technique defies the coaching manuals. Dhoni doesn't have a great footwork. He believes in muscling a full ball to Long-on, Long-off or Midwicket regions rather than driving it to the Cover region. Not only a great smasher of the full length balls, he also is a firm puller and hooker of the short balls, which makes it tough for the bowler to bowl to him. 

== Personal life ==

Dhoni is an introvert and shy person. He was a Ticket checker in South Eastern railway from September 2001 to July 2004 in Kharagpur.His ancestral village is Lwali, which is in Jaiti taluka of  Almora district of the Uttarakhand state. The village has population of 20 to 30 families.  His father Pan Singh Dhoni left the village in 1970 for employment. 


== International records ==


=== Test cricket ===
Under Dhoni's captaincy, India topped the Test cricket rankings for the first time, in 2009.

Dhoni has the most overseas Test defeats by an Indian captain, with 15.
Dhoni is the first Indian wicket-keeper to complete 4,000 Test runs.


=== T20I Cricket ===
Most matches as captain in T20Is(72)
Most matches in T20I history as both captain and wicket-keeper (72)
Most consecutive T20I innings without a duck (84).
Dhoni holds the record for playing the most T20I innings (76) and scored the most runs(1,153) before scoring a fifty.
Most dismissals as wicket-keeper in T20Is (87)
Most catches as wicket-keeper in T20Is (54)
Most stumpings as wicket-keeper in T20Is (33)
Most catches as wicket keeper in a T20I innings (5)

=== Dhoni Entertainment ===
In 2019, Dhoni Entertainment entered into a long-term business agreement with Banijay Asia to produce content in various genres. The first show developed was a documentary web series, titled Roar of The Lion, about the comeback of the Chennai Super Kings to lift the 2018 Indian Premier League starring MS Dhoni in the lead role. The web series is the biggest ever release through the platform of Hotstar Specials and started its online streaming from 20 March 2019.


=== Territorial Army ===

Dhoni holds a honorary rank of Lieutenant Colonel in the Parachute Regiment of the Indian Territorial Army (106 Para TA battalion). The honorary rank was presented to him by the Indian Army in 2011 for his service to the nation as a cricketer.After completing five parachute training jumps from Indian Army aircraft in the Agra training camp, he became a qualified paratrooper in 2015. In August 2019 he completed a two-week stint with the Territorial Army in Jammu and Kashmir.


== Awards and achievements ==


=== National honours ===
2018: Padma Bhushan, India's third-highest civilian award.
2009: Padma Shri, India's fourth-highest civilian award.
2007–08: Major Dhyanchand Khel Ratna award, India's highest honor given for achievement in sports.


=== Sporting honours ===
ICC ODI Player of the Year: 2008, 2009
ICC World ODI XI: 2006, 2008, 2009, 2010, 2011, 2012, 2013, 2014 (captain in 2009, 2011–2014)
Castrol Indian Cricketer of the Year: 2011
ICC Men's ODI team of the decade: 2011 - 2020 (captain and wicketkeeper)
ICC Men's T20I team of the decade: 2011 -2020 (captain and wicketkeeper)
ICC Spirit of the cricket award of the decade: 2011 - 2020


=== Other honours and awards ===
MTV Youth Icon of the Year: 2006
LG People's Choice Award: 2013
Honorary doctorate degree by De Montfort University in August 2011
CNN-News18 Indian of the Year: 2011
In 2019 Jharkhand Cricket association named their stadium's South stand after Dhoni.



== References ==


== External links ==
MS Dhoni at ESPNcricinfo
Mahendra Singh Dhoni at IndianKanoon

To get Data in different languages:

To obtain information in a different language, we will use the set_lang() function with the language specified as an argument.

Here “fr “- indicates the French language.

Approach:

  • Import wikipedia module using the import keyword.
  • Pass some random language(French) as an argument to the set_lang() function to obtain the data in the given language.
  • Pass some random string, no of sentences as the argument to the summary() function.
  • Store it in a variable.
  • Print the above result.
  • The Exit of the Program.

Below is the implementation:

# Import wikipedia module using the import keyword.
import wikipedia
# Pass some random language(French) as an argument to the set_lang() function to
# obtain the data in the given language.
wikipedia.set_lang("fr")
# Pass some random string, no of sentences as the argument to the summary() function.
# Store it in a variable.
sumry = wikipedia.summary('Doremon',sentences="10")
# Print the above result.
print(sumry)

Output:

Doraemon (ドラえもん) est une série de mangas japonais, créée par Fujiko Fujio, par la suite devenue un anime puis une franchise médiatique. La série se centre sur un chat-robot nommé Doraemon, ayant voyagé à travers le temps depuis le futur, afin d'aider un jeune garçon nommé Nobita Nobi (野比 のび太, Nobi Nobita). Le manga est initialement paru dans les marchés japonais en août 1969, lors de sa publication simultanée dans six différents magazines. Un total de 1 344 scénarios ont été créés pour la série, publiés par Shogakukan sous la branche Tentōmushi (てんとう虫), puis adaptés en quarante-cinq volumes. Les volumes sont conservés à la bibliothèque centrale de Takaoka, au Japon, la ville natale de Fujiko Fujio. Il s'agit par ailleurs de l'un des mangas les mieux vendus dans le monde, avec plus de 100 millions d'exemplaires, et de l'une des bandes dessinées les plus vendues au monde. La société américaine Turner Broadcasting System rachète les droits de l'anime Doraemon au milieu des années 1980 pour une parution en langue anglaise, mais annule sans explication sa programmation. La majeure partie des épisodes de Doraemon appartiennent au domaine de la comédie et des valeurs morales telles que l'honnêteté, la persévérance, le courage et le respect. De nombreux problèmes sociétaux et environnementaux sont souvent visités, comme l'abandon d'animaux, le réchauffement climatique, les espèces menacées, la déforestation, et la pollution. De nombreux sujets historiques comme la préhistoire et l'histoire du Japon sont également visités.