How to remove query from URL w/ Python

Py3

from urllib.parse import urlparse, parse_qs

url = "http://example.com/foobar?a=1&b=2&c=3"

print(urljoin(url, urlparse(url).path))

Note: this method is not working with URL like http://example.com?a=1&b=2&c=3, because .path returns empty string which doesn't active the urljoin function. Will update here if got other solutions.

你可能感兴趣的:(How to remove query from URL w/ Python)