Last active
February 4, 2018 09:36
-
-
Save toniher/a44384bfd2927a78448d2182eebd305e to your computer and use it in GitHub Desktop.
Simple Python script for extraction es wikipedia extract text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import requests | |
import urllib | |
pagename = str( ' '.join( sys.argv[1:] ) ) | |
wikiurl = "https://es.wikipedia.org/w/api.php?action=query&format=json&titles="+urllib.quote_plus( pagename )+"&prop=extracts&exintro&explaintext&redirects=true" | |
r = requests.get(wikiurl) | |
data = json.loads( r.content ) | |
if data : | |
if 'query' in data : | |
if 'pages' in data['query'] : | |
for key in data['query']['pages'] : | |
page = data['query']['pages'][key] | |
if 'extract' in page : | |
extract = page['extract'] | |
print extract.encode('utf-8') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment