Skip to content

Commit 78e6d6d

Browse files
committed
add access wikipedia in python tutorial
1 parent af9ee16 commit 78e6d6d

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ This is a repository of all the tutorials of [The Python Code](https://www.thepy
3232
- [How to Control your Keyboard in Python](https://www.thepythoncode.com/article/control-keyboard-python). ([code](general/keyboard-controller))
3333
- [How to Make a Process Monitor in Python](https://www.thepythoncode.com/article/make-process-monitor-python). ([code](general/process-monitor))
3434
- [How to Make a Screen Recorder in Python](https://www.thepythoncode.com/article/make-screen-recorder-python). ([code](general/screen-recorder))
35+
- [How to Access Wikipedia in Python](https://www.thepythoncode.com/article/access-wikipedia-python). ([code](general/wikipedia-extractor))
3536

general/wikipedia-extractor/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# [How to Access Wikipedia in Python](https://www.thepythoncode.com/article/access-wikipedia-python)
2+
To run this:
3+
- `pip3 install -r requirements.txt`
4+
- `python3 wikipedia_extractor.py`
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
wikipedia
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import wikipedia
2+
3+
# print the summary of what python is
4+
print(wikipedia.summary("Python Programming Language"))
5+
6+
# search for a term
7+
result = wikipedia.search("Neural networks")
8+
print("Result search of 'Neural networks':", result)
9+
10+
# get the page: Neural network
11+
page = wikipedia.page(result[0])
12+
13+
# get the title of the page
14+
title = page.title
15+
16+
# get the categories of the page
17+
categories = page.categories
18+
19+
# get the whole wikipedia page text (content)
20+
content = page.content
21+
22+
# get all the links in the page
23+
links = page.links
24+
25+
# get the page references
26+
references = page.references
27+
28+
# summary
29+
summary = page.summary
30+
31+
# print info
32+
print("Page content:\n", content, "\n")
33+
print("Page title:", title, "\n")
34+
print("Categories:", categories, "\n")
35+
print("Links:", links, "\n")
36+
print("References:", references, "\n")
37+
print("Summary:", summary, "\n")
38+

0 commit comments

Comments
 (0)