URL query parameters to dict python

Use the urllib.parse library: >>> from urllib import parse >>> url = “http://www.example.org/default.html?ct=32&op=92&item=98″ >>> parse.urlsplit(url) SplitResult(scheme=”http”, netloc=”www.example.org”, path=”/default.html”, query=’ct=32&op=92&item=98′, fragment=””) >>> parse.parse_qs(parse.urlsplit(url).query) {‘item’: [’98’], ‘op’: [’92’], ‘ct’: [’32’]} >>> dict(parse.parse_qsl(parse.urlsplit(url).query)) {‘item’: ’98’, ‘op’: ’92’, ‘ct’: ’32’} The urllib.parse.parse_qs() and urllib.parse.parse_qsl() methods parse out query strings, taking into account that keys can occur more than once … Read more

How to get a URL parameter in Express?

Express 4.x To get a URL parameter’s value, use req.params app.get(‘/p/:tagId’, function(req, res) { res.send(“tagId is set to ” + req.params.tagId); }); // GET /p/5 // tagId is set to 5 If you want to get a query parameter ?tagId=5, then use req.query app.get(‘/p’, function(req, res) { res.send(“tagId is set to ” + req.query.tagId); }); … Read more