I am trying to parse a list of email addresses to remove the username and '@' symbol only leaving the domain name.
Example: [email protected] Desired output: gmail.com
I have accomplished this with the following code:
for row in cr: emailaddy = row[0] (emailuser, domain) = row[0].split('@') print domain but my issue is when I encounter a improperly formatted email address. For example if the row contains "aaaaaaaaa" (instead of a valid email address) the program crashes with the error
(emailuser, domain) = row[0].split('@') ValueError: need more than 1 value to unpack. (as you would expect) Rather than check all the email addresses for their validity, I would rather just not update grab the domain and move on to the next record. How can I properly handle this error and just move on?
So for the list of:
[email protected] [email protected] youououou [email protected] I would like the output to be:
gmail.com hotmail.com yahoo.com Thanks!
rfind("@")or something..