0

a=[('https://www.google.co.in/search?q=kite+zerodha&oq=kite%2Cz&aqs=chrome.1.69i57j0l5.4766j0j7&sourceid=chrome&ie=UTF-8', 1), ('https://kite.zerodha.com/', 1), ('https://kite.trade/connect/login?api_key=xyz', 1)]

how to get value of api_key which is xyz from above mentioned a. please help me to write code in python.Thank you

2 Answers 2

1

Just looping over all elements and parsing url to get the api_key, have a look into below code:

from urlparse import urlparse, parse_qs

a=[('https://www.google.co.in/search?q=kite+zerodha&oq=kite%2Cz&aqs=chrome.1.69i57j0l5.4766j0j7&sourceid=chrome&ie=UTF-8', 1), ('https://kite.zerodha.com/', 1), ('https://kite.trade/connect/login?api_key=xyz', 1)]
for value in a:
    if len(value) > 1:
        url = value[0]
        if 'api_key' in parse_qs(urlparse(url).query).keys():
            print parse_qs(urlparse(url).query)['api_key'][0]

output:

xyz
Sign up to request clarification or add additional context in comments.

Comments

0

This will work too. Hope this helps.

  • Find all items that has the keyword 'api_key' (in url[0]),
  • Split it into columns, delimited by '=' (split by '=')
  • The last entry ([-1]) will be the answer (xyz).
a=[('https://www.google.co.in/search?q=kite+zerodha&oq=kite%2Cz&aqs=chrome.1.69i57j0l5.4766j0j7&sourceid=chrome&ie=UTF-8', 1), ('https://kite.zerodha.com/', 1), ('https://kite.trade/connect/login?api_key=xyz', 1)]
for ky in [url for url in a if 'api_key' in url[0]]:
    print(ky[0].split('=')[-1])


Sample result: xyz

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.