=== modified file 'examples/myspace.py' --- examples/myspace.py 2007-06-12 18:51:30 +0000 +++ examples/myspace.py 2007-06-12 21:28:10 +0000 @@ -4,12 +4,12 @@ is a fair bit nicer! """ # in case pykhtml isn't already installed -import sys, codecs +import sys sys.path.append("..") +import re import pykhtml -#pykhtml.debugWithGUI = True -#pykhtml.useXvfb = True + def login(email, password, browser): #print "Here" @@ -74,6 +74,22 @@ if anchor.text.strip().isdigit(): print "Number of friends:", anchor.text.strip() break + # and finally (and quite trickily, this is pretty fragile) the + # date of the last login. + # firstly, we create a regular expression that will match a + # date of the form (1 or 2 numbers)/(2 numbers)/(4 numbers) + dateExpression = re.compile("\d{1,2}/\d{2}/\d{4}") + # we know the date is in a span in a div with a class of + # 'section', so: + for div in document.getElementsByClass("section", "div"): + for span in div.getElementsByTagName("span"): + # if there is text for this span: + if span.text: + # and the regular expression matches: + match = dateExpression.search(span.text) + if match: + print "Last login:", match.group() + break pykhtml.stopEventLoop() def signedOut(browser): === modified file 'pykhtml/__init__.py' --- pykhtml/__init__.py 2007-05-06 15:05:28 +0000 +++ pykhtml/__init__.py 2007-06-12 21:28:10 +0000 @@ -346,7 +346,7 @@ onNextLoad = property(_getOnNextLoad, _setOnNextLoad, None, "If you're going to do something that will inadvertently cause PyKHTML to browse to a new page and you want a function to be called when the page is loaded, set onNextLoad to the function") def _slotDocCreated(self): - self.part.executeScript(DOM.Node(), "window.alert = function() {}") + self.part.executeScript(DOM.Node(), "window.alert = function() {}; window.prompt = function() {}") self.disconnect(self.part, qt.SIGNAL("docCreated()"), self._slotDocCreated) if not self.loadFunction: raise AttributeError("No load function callback present")