Easy way to use Wikipedia in Python

Execution environment

python = 3.8.1 windows

Installation method

pip install wikipedia

How to use

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

Grammar

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)

reference

More details can be found here. https://pypi.org/project/wikipedia/

Recommended Posts

Easy way to use Wikipedia in Python
Easy way to customize Python import
How to use SQLite in Python
How to use Mysql in python
How to use ChemSpider in Python
How to use PubChem in Python
Easy to use Jupyter notebook (Python3.5)
[Introduction to Python] How to use class in Python?
How to use __slots__ in Python class
How to use regular expressions in Python
How to use is and == in Python
An easy way to hit the Amazon Product API in Python
Use config.ini in Python
Easy to use Flask
Use Valgrind in Python
Easy to use SQLite3
Use profiler in Python
How to use the C library in Python
How to use Python Image Library in python3 series
Summary of how to use MNIST in Python
A clever way to time processing in Python
Use cryptography module to handle OpenSSL in Python
The easiest way to use OpenCV with python
How to use tkinter with python in pyenv
An easy way to call Java from Python
Use os.getenv to get environment variables in Python
Let's use def in python
Easy way to check the source of Python modules
[For beginners] How to use say command in python!
Use let expression in Python
Use Measurement Protocol in Python
To flush stdout in Python
python3: How to use bottle (2)
Use callback function in Python
Use parameter store in Python
[Python] How to use list 1
Login to website in Python
Connect to Wikipedia with Python
Use HTTP cache in Python
Use list-keyed dict in Python
Easy way to scrape with python using Google Colab
How to use Python argparse
Use regular expressions in Python
Use Spyder in Python IDE
Python: How to use pydub
[Python] How to use checkio
Speech to speech in python [text to speech]
[Python] Another way to import
I tried to summarize how to use pandas in python
Easy way to rename files
How to use the model learned in Lobe in Python
Easy password box in Python
How to develop in Python
Easy to use E-Cell 4 Intermediate
[Python] How to use input ()
How to use Python lambda
[Python] How to use virtualenv
python3: How to use bottle (3)
I want to use the R dataset in python
python3: How to use bottle
Post to Slack in Python