def serialize(url='', data={}):
""" Returns a URL with a query string of the given data.
"""
p = urlparse.urlsplit(url)
q = urlparse.parse_qsl(p.query)
q.extend((b(k), b(v)) for k, v in sorted(data.items()))
q = urlencode(q, doseq=True)
p = p.scheme, p.netloc, p.path, q, p.fragment
s = urlparse.urlunsplit(p)
s = s.lstrip('?')
return s
# print(serialize('http://www.google.com', {'q': 'cats'})) # http://www.google.com?q=cats
#---- REQUESTS & STREAMS --------------------------------------------------------------------------
# The download(url) function returns the HTML (JSON, image data, ...) at the given url.
# If this fails it will raise NotFound (404), Forbidden (403) or TooManyRequests (420).
评论列表
文章目录