-3

I need your help on this, I have a url something like this

url = "https://tracking.example.com:443/attribution_tracking/conversions/1980.js?p=https://example.com/search?addsearch=test+search&e="

Need some python code to extract the url parameters and the result would be an array something like this

extracted_parameters = ["p=", "addsearch=", "e="]
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Eric John E.
  • 73
  • 1
  • 1
  • 7
  • How do you know if the e parameter is a query parameter of the parent url or of the p url? – Riccardo Bucco Nov 25 '21 at 11:39
  • I am thinking about using regex with a character starting with '?', ends with '=' and words starts with '&' ends with '=' but I don't know how to implement in the code. – Eric John E. Nov 25 '21 at 11:45

1 Answers1

0

This uses splitting.

url = "https://tracking.example.com:443/attribution_tracking/conversions/1980.js?p=https://example.com/search?addsearch=test+search&e="

def extract(url):
    ret = []
    p = url.split('p=')[1].split('addsearch')[0]
    addsearch = url.split('addsearch=')[1].split('e=')[0]
    e = url.split('e=')[1]

    ret.append(p)
    ret.append(addsearch)
    ret.append(e)
    
    return ret


# start
res = extract(url)
print(res)

Output

['https://example.com/search?', 'test+search&', '']
ferdy
  • 4,396
  • 2
  • 4
  • 16