- To get the content of a Wikipedia page using the Wikipedia module in Python, you can use the page.content attribute. This attribute returns the full text of the page as a string. Here's an example of how you can get the content of a page and print it:
- import wikipedia
- # Search for pages that match the search term
- results = wikipedia.search("search term")
- # Get the best page from the search results
- page = wikipedia.page(results[0])
- # Print the page's content
- print(page.content)
- You can also access other useful data fields for a Wikipedia page using the page object. Here are some examples of data fields that you can access:
- page.title: the title of the page
- page.url: the URL of the page
- page.summary: a summary of the page's content
- page.images: a list of URLs for images on the page
- page.links: a list of URLs for links on the page
- page.references: a list of URLs for references on the page
- page.categories: a list of categories for the page
- Here's an example of how you can access and print some of these data fields:
- import wikipedia
- # Search for pages that match the search term
- results = wikipedia.search("search term")
- # Get the best page from the search results
- page = wikipedia.page(results[0])
- # Print the page's title, URL, summary, and list of images
- print(page.title)
- print(page.url)
- print(page.summary)
- print(page.images)
- You can access any of the data fields listed above using the same syntax. Just replace field_name with the name of the field you want to access.
- Watch: How to Make a Wikipedia Client in python - Wikipedia API tutorial:
Python software and documentation are licensed under the PSF License Agreement.
Starting with Python 3.8.6, examples, recipes, and other code in the documentation are dual licensed under the PSF License Agreement and the Zero-Clause BSD license.
Some software incorporated into Python is under different licenses. The licenses are listed with code falling under that license. See Licenses and Acknowledgements for Incorporated Software for an incomplete list of these licenses.
Python and it's documentation is:
Copyright © 2001-2022 Python Software Foundation. All rights reserved.
Copyright © 2000 BeOpen.com. All rights reserved.
Copyright © 1995-2000 Corporation for National Research Initiatives. All rights reserved.
Copyright © 1991-1995 Stichting Mathematisch Centrum. All rights reserved.
See History and License for complete license and permissions information:
https://docs.python.org/3/license.html#psf-license