Can parse JSON web pages

This commit is contained in:
Némunaire 2012-11-06 04:26:38 +01:00
parent 02bebb663c
commit 88d976fb60

View file

@ -17,6 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import http.client
import json
import re
import socket
from urllib.parse import quote
@ -130,6 +131,14 @@ def getXML(url, timeout=15):
else:
return xmlparser.parse_string(cnt)
def getJSON(url, timeout=15):
"""Get content page and return JSON content"""
cnt = getURLContent(url, timeout)
if cnt is None:
return None
else:
return json.loads(cnt.decode())
def traceURL(url, timeout=5, stack=None):
"""Follow redirections and return the redirections stack"""
if stack is None: