forked from geekcomputers/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WikipediaModule.py
89 lines (74 loc) · 2.08 KB
/
WikipediaModule.py
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
"""
Created on Sat Jul 15 01:41:31 2017
@author: Albert
"""
from __future__ import print_function
import wikipedia as wk
from bs4 import BeautifulSoup
def wiki():
"""
Search Anything in wikipedia
"""
word = input("Wikipedia Search : ")
results = wk.search(word)
for i in enumerate(results):
print(i)
try:
key = int(input("Enter the number : "))
except AssertionError:
key = int(input("Please enter corresponding article number : "))
page = wk.page(results[key])
url = page.url
# originalTitle=page.original_title
pageId = page.pageid
# references=page.references
title = page.title
# soup=BeautifulSoup(page.content,'lxml')
pageLength = input("""Wiki Page Type : 1.Full 2.Summary : """)
if pageLength == 1:
soup = fullPage(page)
print(soup)
else:
print(title)
print("Page Id = ", pageId)
print(page.summary)
print("Page Link = ", url)
# print "References : ",references
pass
def fullPage(page):
soup = BeautifulSoup(page.content, "lxml")
return soup
def randomWiki():
"""
This function gives you a list of n number of random articles
Choose any article.
"""
number = input("No: of Random Pages : ")
lst = wk.random(number)
for i in enumerate(lst):
print(i)
try:
key = input("Enter the number : ")
assert key >= 0 and key < number
except AssertionError:
key = input("Please enter corresponding article number : ")
page = wk.page(lst[key])
url = page.url
# originalTitle=page.original_title
pageId = page.pageid
# references=page.references
title = page.title
# soup=BeautifulSoup(page.content,'lxml')
pageLength = input("""Wiki Page Type : 1.Full 2.Summary : """)
if pageLength == 1:
soup = fullPage(page)
print(soup)
else:
print(title)
print("Page Id = ", pageId)
print(page.summary)
print("Page Link = ", url)
# print "References : ",references
pass
# if __name__=="__main__":
# wiki()