import sys
sys.path.append("..")
import pykhtml
# the HTML document we're gonna load. Notice that
# it contains javascript and manipulates the DOM
page = """
Test
"""
def checkForDomChanges(browser, previousData):
data = browser.document.serialized
if data != previousData:
print "DOM changed!"
print "New text:", repr(browser.document.getElementById("mydiv").text)
pykhtml.stopEventLoop()
else:
print "DOM not changed. Checking in 1 second..."
pykhtml.timer(1, pykhtml.partial(checkForDomChanges, browser, data))
def main():
browser = pykhtml.Browser()
# load our markup
browser.setHtml(page)
# to see if the DOM has changed we poll and access
# browser.document.serialized and compare it to
# the previous calling. Note the use of pykhtml.partial
# to bind the serialised data to the function
pykhtml.timer(1, pykhtml.partial(checkForDomChanges, browser, browser.document.serialized))
pykhtml.startEventLoop()
if __name__ == "__main__":
main()