Skip to content

Instantly share code, notes, and snippets.

@nikhiljha
Created March 25, 2016 02:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikhiljha/52935ad096ac3e07ec73 to your computer and use it in GitHub Desktop.
Save nikhiljha/52935ad096ac3e07ec73 to your computer and use it in GitHub Desktop.
Look up things on Wikipedia in the command line!
# Usage: python wikipedia.py
# Look up things on Wikipedia in the command line!
import requests;
import json;
learn = input('Learn About ')
for x in learn:
if x == ' ':
x = '%20'
r = requests.get('https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro=&explaintext=&redirects=1&titles=' + learn);
parse = json.loads(r.content.decode('utf-8'));
pages = parse['query']['pages'];
text = 'error';
for n in pages:
text = parse['query']['pages'][n]['extract'];
print(text.encode('utf-8').decode('utf-8'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment