我只是得到错误:
AttributeError: SecondLife instance has no attribute 'sendAMail'
怎么了?(我检查了格式,这不是错误。我检查了语法,也没有错误。)
脚本中发生的是一个 url 用 cookie 打开,我想从中获取一些信息。
import urllib2, cookielib, re
import ClientForm
import re
import smtplib
kurse = ['Entwicklung von Multimediasystemen', 'Computergrafik', 'Gestaltung von Multimediasystemen', 'Verteilte Systeme']
class SecondLife:
def __init__(self, usernames, password):
self.username = usernames
self.password = password
self.url = 'https://lsf.htw-berlin.de/qisserver/rds?state=user&type=0&application=QISPOS'
cookiejar = cookielib.LWPCookieJar()
cookiejar = urllib2.HTTPCookieProcessor(cookiejar)
# debugger = urllib2.HTTPHandler(debuglevel=1)
opener = urllib2.build_opener(cookiejar)
urllib2.install_opener(opener)
def sendAMail(self, smtp_server, user, password, listener, subject, text):
smtp = smtplib.SMTP(smtp_server)
smtp.starttls()
smtp.login(user,password)
msg = "SUBJECT: " + subject + "\n\n" + text
smtp.sendmail("bln.schade@gmail.com", listener, msg)
smtp.quit()
def login(self):
response = urllib2.urlopen(self.url)
forms = ClientForm.ParseResponse(response, backwards_compat=False)
# forms[0] is 'GET', forms[1] is 'POST'
form = forms[0]
try:
form['username'] = self.username
form['password'] = self.password
except Exception, e:
print 'The following error occured: \n"%s"' % e
print
print 'A good idea is to open a browser and see if you can log in from there.'
print 'URL:', self.url
exit()
self.page = urllib2.urlopen(form.click('submit')).read()
def friends_online(self):
self.login()
final = ""
final_asi = ""
leistungsstand = ""
match = re.search(r"asi=\w*\d*\"", self.page)
if match:
final = match.group()
final_asi = re.sub("asi=", "", final)
final_asi = re.sub("\"", "", final_asi)
print "vorher: " + final
print "nachher: " + final_asi
leistungsstand_url = "https://lsf.htw-berlin.de/qisserver/rds?state=htmlbesch&application=sospos&moduleParameter=Student&navigationPosition=functions%2Cnotenspiegel&breadcrumb=notenspiegel&topitem=functions&subitem=notenspiegel&asi=" + final_asi
leistungsstand = urllib2.urlopen(leistungsstand_url).read()
else:
print "not match"
# Ausloggen
logout = "https://lsf.htw-berlin.de/qisserver/rds?state=user&type=4&re=last&menuid=logout&category=auth.logout"
urllib2.urlopen(logout).read()
website = open("lsf.html", "w")
website.write(leistungsstand)
website.close()
for kurs in kurse:
print kurs
if (re.search(kurs, "fajfjsjj Entwicklung von Multimediasystemen hahahah")):
self.sendAMail("smtp.googlemail.com", "user", "passw", "bln.schade@gmail.com", "kurs" , "Eine neue Note ist im LSF eingetragen.")
#self.final_asi.replace(new, "asi=","")
#asi[0].replace("\"","")
#print "Final " + asi
SL = SecondLife('xyz', 'xyz')
SL.friends_online()