1

how do i extract certain word in bold below and store the value as input? i managed to get url value as it has referer: text, i would like take value that starting from 1st until it meet '=' sign that is username and continue to catch text start from '&' until '=' which is password?

username=hello&password=test1

3
  • Is it always like 5? Is the value always username and password? Commented Mar 27, 2020 at 17:56
  • @HarshalParekh it always in line 5 but the username and password is variables/changeable. that why i want to get text in line 5 from 1st to '=' sign and continue from '&' sign to '=' sign..that store as 2 variables respectively.. Commented Mar 27, 2020 at 18:17
  • Does this answer your question? Retrieving parameters from a URL Commented Mar 27, 2020 at 19:01

1 Answer 1

0
for i, line in enumerate(f):  
    # line 5
    if i == 4:
        # get the value from the start of the string to the first "="
        username = line[:line.index('=')]

        # get the value starting from the "&" to the second "="
        password = line[line.index('&') + 1:line.index('=', line.index('=') + 1)]

        print(username, password)

More on index and substring.

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

3 Comments

i know if we have static 'username' and 'password' text, but 'username' and 'password' are not static.But 'username' sometime maybe can be uname' and so on..
Then you can use the same logic on line 5. You can check my edit.
thank you.....it works

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.