Is there a better way to write this URL Manipulation in Python?

前端 未结 2 2294
梦毁少年i
梦毁少年i 2021-02-20 15:42

I\'m curious if there\'s a simpler way to remove a particular parameter from a url. What I came up with is the following. This seems a bit verbose. Libraries to use or a more py

2条回答
  •  孤街浪徒
    2021-02-20 16:04

    Use urlparse.parse_qsl() to crack the query string. You can filter this in one go:

    params = [(k,v) for (k,v) in parse_qsl(parsed.query) if k != 'page']
    

提交回复
热议问题