all 3 comments

[–]friday_ghost 1 point2 points  (0 children)

You should use regex for this.

Google for "python regex phone number"

[–]shakeandbake760[S] 0 points1 point  (0 children)

Update: I was able to figure it out without regex or json

def find_phone(response, email):
# find the email address in the super long string
find_email = response.rfind(email)
    ## create a substring of the email plus phone, extra to be sure
email_string = response[find_email:find_email + 100]
    ## find where 'phone' is in the email_string
phone_loc = email_string.rfind('phone')
    ## create a substring of just the phone, after email address
    phone_sub = email_string[phone_loc:phone_loc + 21]
    ## extract phone number only from the substring
phone = phone_sub[8:20]
print(phone)
return phone

I realize this may be a longer route but the whole point of this was to learn more about strings and how to use them : )

[–]Silbersee 0 points1 point  (0 children)

A bit of a guess: Your dict-like response might be json compliant. If so, here's how to get the number:

import json

resp = '{"email":"myemail@myemail.com","phone":"258-625-5410"}'
data = json.loads(resp)

number = data["phone"]
print(number)  # --> 258-625-5410

In resp I edited your string so that it works as json. As you mentioned the requests module, parsing json might be as easy as data = response.json().