Make a JavaScript array from URL

URL to array: (adapted from my answer here) function URLToArray(url) { var request = {}; var pairs = url.substring(url.indexOf(‘?’) + 1).split(‘&’); for (var i = 0; i < pairs.length; i++) { if(!pairs[i]) continue; var pair = pairs[i].split(‘=’); request[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]); } return request; } Array to URL: function ArrayToURL(array) { var pairs = []; for … Read more

How to catch 404 error in urllib.urlretrieve

Check out urllib.urlretrieve‘s complete code: def urlretrieve(url, filename=None, reporthook=None, data=None): global _urlopener if not _urlopener: _urlopener = FancyURLopener() return _urlopener.retrieve(url, filename, reporthook, data) In other words, you can use urllib.FancyURLopener (it’s part of the public urllib API). You can override http_error_default to detect 404s: class MyURLopener(urllib.FancyURLopener): def http_error_default(self, url, fp, errcode, errmsg, headers): # handle … Read more

Parse URL in shell script

[EDIT 2019] This answer is not meant to be a catch-all, works for everything solution it was intended to provide a simple alternative to the python based version and it ended up having more features than the original. It answered the basic question in a bash-only way and then was modified multiple times by myself … Read more