Skip to content Skip to sidebar Skip to footer

Execute Js Code On Page From Python

My task is to get a list of named functions from any web-page using Python. I have a script written using JavaScript. It does what I need. When page is loaded I can run the script

Solution 1:

I have solved the problem with the using of selenium.

Then I have downloaded the PhantomJS driver to use selenium without a browser window and added it to PATH.

Finally, I use the following Python script:

from selenium import webdriver
    
myscript = settings.get_js_code() # here I get content of *.js file
driver = webdriver.PhantomJS()
driver.get(url)
result = driver.execute_script(myscript)
driver.quit()

Note: your script have to return something to get the result.

Post a Comment for "Execute Js Code On Page From Python"