1 Star 0 Fork 0

wdc/Python001

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
WikipediaModule.py 2.08 KB
一键复制 编辑 原始数据 按行查看 历史
Jérôme Krell 提交于 2019-10-10 14:22 . Reformat Code by PyCharm-Community
"""
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()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ijiwei/Python001.git
git@gitee.com:ijiwei/Python001.git
ijiwei
Python001
Python001
master

搜索帮助