Ai
1 Star 0 Fork 0

dzc/Python-1

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
WikipediaModule.py 2.08 KB
一键复制 编辑 原始数据 按行查看 历史
cclauss 提交于 2019-03-12 16:17 +08:00 . Use print() function in both Python 2 and Python 3
"""
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=raw_input("Wikipedia Search : ")
results=wk.search(word)
for i in enumerate(results):
print(i)
try:
key=input("Enter the number : ")
except AssertionError:
key=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()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sdredboy/Python-1.git
git@gitee.com:sdredboy/Python-1.git
sdredboy
Python-1
Python-1
master

搜索帮助