File tree Expand file tree Collapse file tree 4 files changed +44
-0
lines changed Expand file tree Collapse file tree 4 files changed +44
-0
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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 `
Original file line number Diff line number Diff line change 1+ wikipedia
Original file line number Diff line number Diff line change 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+
You can’t perform that action at this time.
0 commit comments