简体   繁体   中英

Python urlparse.unparse_qsl?

In Python's urlparse, you can use urlparse to parse the URL, and then parse_qsl to parse the query.

I want to remove a query (name, value) pair, and then reconstruct the URL.

There is a urlunparse method, but no unparse_qsl method.

What is the correct way to reconstruct the query from the qsl list?

函数urllib.urlencode是合适的。

>>> urlparse.parse_qsl('q=stackoverflow')
[('q', 'stackoverflow')]

>>> urllib.urlencode(urlparse.parse_qsl('q=stackoverflow'))
'q=stackoverflow'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM