-1

I have multiple links

www.example.com/abc?file=xxxxxxxxxxxxxxx&url=xxxxxxxxxxxxxxx
www.example.com/abc?google=xxxxxxxxxxxxxxx&fb=xxxxxxxxxxxxxxx

etc Now i want to change these parameter value to "xxxxxxxxxxxxxxx" how can i do that? all parameters are different and in other requests they will change as well

1 Answers1

0

here is a working example:

import urllib.parse as urlparse
from urllib.parse import parse_qs


def replace_params_with_x(url):
    parsed = urlparse.urlparse(url)
    params= parse_qs(parsed.query)
    modified_params={key : ["x" * len (val) for val in values] for key, values in params.items()}

    url_modified=url.split("?")[0]
    # i have params
    rplc = "&".join([ "%s=%s" % (key, val) for key, values in modified_params.items() for val in values ])
    if rplc:
        url_modified += "?" +rplc


    return url_modified

# example on a single url (applicable to any url)
url = 'www.example.com/abc?file=my_file&url=my_url'
print(replace_params_with_x(url))

output: www.example.com/abc?&file=xxxxxxx&url=xxxxxx

Cryptoharf84
  • 371
  • 1
  • 12