forked from chavarera/PythonScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.BasicOfWikipedia.py
More file actions
60 lines (34 loc) · 1.39 KB
/
1.BasicOfWikipedia.py
File metadata and controls
60 lines (34 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'''
created by:Ravishankar Chavare
To install wikipedia use pypi open command prompt and type
pip install wikipedia
To import into python program use
import wikipedia
'''
import wikipedia
#To search a simple query on wikipedia
#use wikipedia.search("keyword")
searched_data=wikipedia.search("India")
print(searched_data)
'''
output according to keyword
['India', 'Irreligion in India', 'East India Company', 'Constitution of India',
'Government of India', 'Christianity in India', 'Savdhaan India', 'Star India',
'States and union territories of India', 'Retailing in India']
'''
#get fewer or more results by using the results kwarg:
#Example wikipedia.search("keyword", results=count)
print(wikipedia.search("India",results=3))
#To get the short description of keyword use summary method like
#wikipedia.summary("keyword")
info_india=wikipedia.summary("india")
print(info_india)
#Some Basic Exception Handeling IF You searched a keyword which is not available
#then it will generate exception with some suggested keyword use wikipedia.exceptions.DisambiguationError exceptions for getting options
try:
mercury=wikipedia.summary("Mercury")
except wikipedia.exceptions.DisambiguationError as e:
ask_user=str(input("Given keyword not found we found some keyword regarding your search do you want y/n"))
if(ask_user=='y'):
print(len(e.options));
print(e.options)