PyV8, can I manipulate the structure of the DOM?

Suppose we have PyV8:

import PyV8
ctxt = PyV8.JSContext()

and python DOM structures e.g. xml.dom

How can I transfer the .js file to PyV8 so that it can change the DOM structure that I have.
If I had this content:

$("#id").remove();

I want to remove the dom element.

PyV8 has a great hello-world example. But I would like to see something useful.

To be clear, I want to do the following:
"Javascript file"→ - magic → -DOM, (already built with html file) and changed now with passed javascript file

+5
source share
2 answers

Formatting applications. I defended as best as possible, but my on-screen reader does not like SO formatters.

, . , , , . , HTML Javascript , . , Python xml DOM, W3C DOM . PyV8 w3c.py dom DOM. W3C Sample Dom , . BeautifulSoup . - lxml.etree target parser. LXML Target Parser " ". HTML/ Script LXML, , , , DOM.

. ( , HTML , , ).

class domParser(object):
    def __init__(self):
    #initialize dom object here, and obtain the root for the destination file object.
        self.dom = newAwesomeCompliantDom()
        self.document = self.dom.document
        self.this = self.document

    def comment(self, commentText):
    #add commentText to self.document or the above dom object you created
        self.this.appendChild(self.document.DOMImplementation.createComment(commentText))

    def start(self, tag, attrs):
    #same here
        self.this = self.this.appendChild(self.document.DOMImplimentation.newElement(tag,attrs))

    def data(self, dataText):
    #append data to the last accessed element, as a new Text child
        self.this.appendChild(self.document.DOMImpl.createDataNode(dataText))

    def end(self):
    #closing element, so move up the tree
        self.this = self.this.parentNode

    def close(self):
        return self.document

#unchecked, please validate yourself
x = lxml.etree.parse(target=domParser)
x.feed(htmlFile)
newDom = x.close()
+2

, , :

https://github.com/buffer/thug

- python, JS PyV8 , .

+4

All Articles