Skip to content

Commit 9dd098e

Browse files
Merge pull request #201 from abrahamalbert18/master
Wikipedia Module
2 parents 87d0162 + 555d55f commit 9dd098e

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

WikipediaModule

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
"""
2+
Created on Sat Jul 15 01:41:31 2017
3+
4+
@author: Albert
5+
"""
6+
import wikipedia as wk
7+
from bs4 import BeautifulSoup
8+
9+
def wiki():
10+
'''
11+
Search Anything in wikipedia
12+
'''
13+
14+
word=raw_input("Wikipedia Search : ")
15+
results=wk.search(word)
16+
for i in enumerate(results):
17+
print i
18+
try:
19+
key=input("Enter the number : ")
20+
except AssertionError:
21+
key=input("Please enter corresponding article number : ")
22+
23+
page=wk.page(results[key])
24+
url=page.url
25+
#originalTitle=page.original_title
26+
pageId=page.pageid
27+
#references=page.references
28+
title=page.title
29+
#soup=BeautifulSoup(page.content,'lxml')
30+
pageLength=input('''Wiki Page Type : 1.Full 2.Summary : ''')
31+
if pageLength==1:
32+
soup=fullPage(page)
33+
print soup
34+
else:
35+
print title
36+
print "Page Id = ",pageId
37+
print page.summary
38+
print "Page Link = ",url
39+
#print "References : ",references
40+
41+
42+
pass
43+
44+
def fullPage(page):
45+
soup=BeautifulSoup(page.content,'lxml')
46+
return soup
47+
48+
def randomWiki():
49+
'''
50+
This function gives you a list of n number of random articles
51+
Choose any article.
52+
'''
53+
number=input("No: of Random Pages : ")
54+
lst=wk.random(number)
55+
for i in enumerate(lst):
56+
print i
57+
try:
58+
key=input("Enter the number : ")
59+
assert key>=0 and key<number
60+
except AssertionError:
61+
key=input("Please enter corresponding article number : ")
62+
63+
page=wk.page(lst[key])
64+
url=page.url
65+
#originalTitle=page.original_title
66+
pageId=page.pageid
67+
#references=page.references
68+
title=page.title
69+
#soup=BeautifulSoup(page.content,'lxml')
70+
pageLength=input('''Wiki Page Type : 1.Full 2.Summary : ''')
71+
if pageLength==1:
72+
soup=fullPage(page)
73+
print soup
74+
else:
75+
print title
76+
print "Page Id = ",pageId
77+
print page.summary
78+
print "Page Link = ",url
79+
#print "References : ",references
80+
81+
pass
82+
83+
84+
85+
#if __name__=="__main__":
86+
# wiki()

0 commit comments

Comments
 (0)