import urllib.parse import urllib.request import json __author__ = 'pacien' class Query: def __init__(self, base_url="", params={}, encoding="utf8"): self.base_url = base_url self.params = params self.encoding = encoding def fetch_raw_result(self): post_query = urllib.parse.urlencode(self.params) post_query = post_query.encode(self.encoding) document = urllib.request.urlopen(self.base_url, post_query) return document.read().decode(self.encoding) class JSONQuery(Query): def fetch_result(self): return json.loads(self.fetch_raw_result())