Uh oh!
There was an error while loading. Please reload this page.
forked from geekcomputers/Python
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWikipediaModule.py
More file actions
Latest commit
88 lines (74 loc) · 2.08 KB
/
Copy pathWikipediaModule.py
File metadata and controls
88 lines (74 loc) · 2.08 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
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
"""
Created on Sat Jul 15 01:41:31 2017
@author: Albert
"""
from __future__ importprint_function
importwikipediaaswk
frombs4importBeautifulSoup
defwiki():
'''
Search Anything in wikipedia
'''
word=input("Wikipedia Search : ")
results=wk.search(word)
foriinenumerate(results):
print(i)
try:
key=int(input("Enter the number : "))
exceptAssertionError:
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 : ''')
ifpageLength==1:
soup=fullPage(page)
print(soup)
else:
print(title)
print("Page Id = ", pageId)
print(page.summary)
print("Page Link = ", url)
# print "References : ",references
pass
deffullPage(page):
soup=BeautifulSoup(page.content, 'lxml')
returnsoup
defrandomWiki():
'''
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)
foriinenumerate(lst):
print(i)
try:
key=input("Enter the number : ")
assertkey>=0andkey<number
exceptAssertionError:
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 : ''')
ifpageLength==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()