python = 3.8.1 windows
pip install wikipedia
import wikipedia
#Taken from a Japanese article
wikipedia.set_lang("ja")
#Fetch the Wiki summary section. auto_If suggest is True, unintended results may be returned.
text = wikipedia.summary("The word you want to search", auto_suggest=False)
#Get the full Wiki.
page = wikipedia.page("The word you want to search", auto_suggest=False)
#page title
page.title
#page URL
page.url
#body of page
page.content
How to edit text content for use in Python
#Installation of regular modules
import re
#Remove furigana
page = re.sub('(.+?)', '', page)
#Get rid of the era.
page = re.sub(' (cf. .+?)。', '', page)
More details can be found here. https://pypi.org/project/wikipedia/
Recommended Posts