Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8101305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:57:03+00:00 2026-06-05T22:57:03+00:00

Lets assume that we have PyV8: import PyV8 ctxt = PyV8.JSContext() and a python

  • 0

Lets assume that we have PyV8:

import PyV8
ctxt = PyV8.JSContext()

and a python DOM structure, for example xml.dom

How can I feed a .js-file to PyV8 so that it could change DOM-structure that I have.
If I had it’s content:

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

I want dom item to be removed.

PyV8 has perfect hello-world example. But I’d like to see something usefull.

To be clear, what I want to do is:
"Javascript file" –>– magic –>– DOM, (already built with html file) and changed now with passed javascript file

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T22:57:04+00:00Added an answer on June 5, 2026 at 10:57 pm

    Appologies for the formatting. I spaced as best I could, but my screen reader doesn’t like SO’s formatting controls.

    I’m going to take a shot at answering your question, though it seems a tad vague. Please let me know if I need to rewrite this answer to fit a different situation.
    I assume you are trying to get an HTML file from the web, and run Javascript from inside this file, to act on said document.
    Unfortunately, none of the Python xml libraries have true DOM support, and W3C DOM compliance is nonexistent in every package I have found.
    What you can do is use the PyV8 w3c.py dom file as a starting example, and create your own full DOM.
    W3C Sample Dom
    You will need to rewrite this module, though, as it does not respect quotes or apostrophys. BeautifulSoup is also not the speediest parser.
    I would recommend using something like lxml.etree’s target parser option.
    LXML Target Parser
    Search for “The feed parser interface”.
    Then, you can load an HTML/Script document with LXML, parse it as below, and run each of the scripts you need on the created DOM.

    Find a partial example below. (Please note that the HTML standards are massive, scattered, and _highly browser specific, so your milage may vary).

    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()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets assume i have a bill number that has 12 numbers: 823 45678912 My
I have a city table that has two columns from_city to_city now lets assume
I have a .jsp page that passes the variable from the servlet. Lets assume
Lets assume that I have a computer which has a multicore processor and a
Hei, So lets assume that I have this ListBox.ItemTemplate: <phone:PhoneApplicationPage.Resources> <DataTemplate x:Key=DataTemplate1> <StackPanel Orientation=Horizontal>
I have created MDI application in Delphi. Lets assume that I have a bunch
Lets say I have a WCF service that a client can use to receive
Lets assume that I have the following configuration in my conf/InjectionConfig.groovy file: x {
For simplicity lets assume that I have a vector of N matrices each of
For the sake of argument , lets assume that I can't change my file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.