import urllib.parse

def process_url(url, keep_params=('CONTENT_ITEM_ID=',)):
    parsed = urllib.parse.urlsplit(url)
filtered_query = '&'.join(qry_item for qry_item in parsed.query.split('&') if
    qry_item.startswith(keep_params))
return urllib.parse.urlunsplit(parsed[:3] + (filtered_query,) + parsed[4:])
Slicing URL with Python