-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="]
2
  • How do you know if the e parameter is a query parameter of the parent url or of the p url? Commented Nov 25, 2021 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. Commented Nov 25, 2021 at 11:45

1 Answer 1

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&', '']
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.