Install wikipedia via pip
masterInstall the wikipedia package using pip to start using the library in your Python projects.
$ pip install wikipediarepository·master·Indexed 25 days ago
https://github.com/goldsmith/wikipediaA Python library for accessing and parsing Wikipedia data by wrapping the MediaWiki API. It provides functionality to search for pages, retrieve summaries, access full page content via WikipediaPage objects, perform geographic searches, and manage language settings and rate limiting. Compatible with Python 2.6+ and 3.3+.
Install the wikipedia package using pip to start using the library in your Python projects.
$ pip install wikipediaTo build the documentation locally, install sphinx, navigate to the docs/ directory, and use make html.
$ pip install sphinx
$ cd docs/
$ make htmlInstall the wikipedia library using pip to access Wikipedia data in your Python projects.
Compatibility:
unittest discover)$ pip install wikipediaTo run the test suite, clone the repository and follow these steps in the root directory:
runtests bash script (covers both Python 2 and 3) or use unittest discover manually.$ pip install -r requirements.txt
$ bash runtests
# OR manual style:
$ python -m unittest discover tests/ '*test.py'When using wikipedia.summary, be prepared to handle two specific exceptions:
wikipedia.exceptions.DisambiguationError: Raised when the query matches multiple distinct pages. You can access the options attribute on the exception object to see the possible matches.wikipedia.exceptions.PageError: Raised when the query does not match any Wikipedia pages.wikipedia.search() to find related page titles and wikipedia.summary() to retrieve a brief overview of a topic. You can limit the number of sentences returned using the sentences parameter.wikipedia.page(title) to retrieve a Page object. This object provides access to the page's title, URL, full content, and a list of links found within the page.Use the wikipedia.summary() function to retrieve a brief summary of a Wikipedia article by providing the article title. This is useful for quickly getting the introductory text of a page.
import wikipedia
print wikipedia.summary("Wikipedia")
# Output: Wikipedia (/ˌwɪkɨˈpiːdiə/ or /ˌwɪkiˈpiːdiə/ WIK-i-PEE-dee-ə) is a collaboratively edited, multilingual, free Internet encyclopedia supported by the non-profit Wikimedia Foundation...donate() function to open a browser window to the Wikipedia donation page.Use wikipedia.set_lang(lang_code) to switch the language of the Wikipedia data being accessed (e.g., 'fr' for French).
import wikipedia
wikipedia.set_lang("fr")
# Subsequent calls will now use the French Wikipediasuggest(query) function to get a list of suggested search terms based on the provided query string.search(query, results=10, suggestion=False) function to find Wikipedia pages matching a specific query. It returns a list of page titles.