forked from x4nth055/pythoncode-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwikipedia_extractor.py
46 lines (34 loc) · 1.13 KB
/
wikipedia_extractor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import wikipedia
# print the summary of what python is
print(wikipedia.summary("Python Programming Language"))
# search for a term
result = wikipedia.search("Neural networks")
print("Result search of 'Neural networks':", result)
# get the page: Neural network
page = wikipedia.page(result[0])
# get the title of the page
title = page.title
# get the categories of the page
categories = page.categories
# get the whole wikipedia page text (content)
content = page.content
# get all the links in the page
links = page.links
# get the page references
references = page.references
# summary
summary = page.summary
# print info
print("Page content:\n", content, "\n")
print("Page title:", title, "\n")
print("Categories:", categories, "\n")
print("Links:", links, "\n")
print("References:", references, "\n")
print("Summary:", summary, "\n")
# changing language
# for a list of available languages,
# check http://meta.wikimedia.org/wiki/List_of_Wikipedias link.
language = "es"
wikipedia.set_lang(language)
# get a page and print the summary in the new language
print(f"Summary of web scraping in {language}:", wikipedia.page("Web Scraping").summary)