Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

execute JS code on page from Python

Status
Not open for further replies.

WildProofGear

Vendor
Jan 8, 2021
1
UA
My job is to get a listing of named features from any web-page using Python. There are some scripts in other languages that do exactly what I need.
When web page is packed I can run the manuscript from JS console (e.g. from dev-tools in GoogleChrome). I have the selection of names of the features as the outcome. Well, however I most likely to the page and perform the manuscript from internet browser manually. However the concern is to do the very same from Python. It can look something like this:

[tt]def get_named_functions_list(url):
myscript = settings.get_js_code() # here I get script that I told above

tool.open(url)

while not tool.document.READY: # here I wait while the page will completely loaded
pass

js_result = tool.execute_from_console(myscript)

return list(js_result.values())


def main():
url = " get_named_functions_list(url)
[/tt]

The result what I want:
1. Request given URL
2. Wait for function document.ready() will finished.
3. Execute javascript on the page (like in browser).
4. Getting of result the JS-code returns.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top