DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

PendEmail

02.14.2009
| 3264 views |
  • submit to reddit
        // Retrieve emails of the people that want to befriend you.

import getpass, sys, os, mechanize, time

browse = mechanize.Browser()
user = raw_input("Bebo username: ")
passw = getpass.getpass("Bebo password: ")
browse.open("http://www.bebo.com/SignIn.jsp")
browse.select_form(nr=1)
browse["EmailUsername"] = user
browse["Password"] = passw
try:
 browse.submit()
except:
    print "Unexpected error occured\nQuitting......."
    sys.exit()
    
if browse.geturl() == "https://secure.bebo.com/JSRedirect.jsp?Location=SignIn.jsp":
 print "Invalid password/username\nQuitting......."
 sys.exit()
else:
 pass

pend = open("Pending.jsp","w")
html = browse.open("http://www.bebo.com/Pending.jsp")
htm = html.read()
pend.write(htm)
pend.close()
browse.close()

mailto = "<a href=mailto:"
file = open("Pending.jsp")
html = file.read()
found = html.find(mailto) 
mail_lst = []

while found > -1:
     mail_lst.append(found)
     found=html.find(mailto, found+1)

file.seek(0)
lenmail = len(mail_lst)-1
mailen = 0
emails = []

while mailen <= lenmail: 
 file.seek(mail_lst[mailen]+15) 
 mbytes = html.find('>')
 email = file.read(mbytes)
 emails.append(email.split(">")[0])
 mailen = mailen+1
 file.seek(0)
 
file.close()
length, statlen = len(emails)-1, len(emails)-1
Ctime,CT = time.ctime(),len(time.ctime())
file=open("emails.txt","a")
file.write("-"*CT+'\n'+Ctime+'\n')

while length >= 0:
    file.write(emails[length]+'\n')
    length -= 1

print "Emails stored in",os.getcwd()+"\n","As 'emails.txt'"