1

I'm not exactly sure how to phrase my question but I'll give it my best shot.

If I load up a webpage, in the HTML it executes a JavaScript file. And if I view the page source I can see the source of that JavaScript (though it's not very well formatted and hard to understand).

Is there a way to run the JavaScript from e.g. Python code, without going through the browser? i.e if I wanted to access a particular function in that JavaScript, is there a clean way to call just that from a Python script, and read the results?

For example... a webpage displays a number that I want access to. It's not in the page source because it's a result from a JavaScript call. Is there a way to call that JavaScript from Python?

Paul D. Waite
99.5k57 gold badges204 silver badges275 bronze badges
asked Jul 10, 2013 at 18:29
7
  • Are you running in the context of the browser? Aka open up the JS console and type the method name. Commented Jul 10, 2013 at 18:31
  • I think you're just looking for the console... Commented Jul 10, 2013 at 18:31
  • 1
    You can install NodeJS and run Javascript without a browser. Commented Jul 10, 2013 at 18:31
  • I probably didn't explain myself clearly enough. I can run the console but if I wanted to access it from another language like python is there a way to do that? I've edited the question to hopefully be more clear Commented Jul 10, 2013 at 18:41
  • are you trying to control an already opened page with python? and send commands to it? Commented Jul 10, 2013 at 18:44

3 Answers 3

1

If you want to scrape a page with javascript in it you've got at least two options:

  • Use selenium to load the page and get the node value you're interested in
  • Use python-spidermonkey to leverage the javascript right from your python script and get the value you're interested in.
answered Jul 10, 2013 at 19:33
Sign up to request clarification or add additional context in comments.

Comments

0

Although your question isn't very clear. I'm guessing that you are trying to access the javascript console.

In Google Chrome:

  • Press F12
  • Go to the 'console' tab

In Mozilla Firefox with Firebug installed:

  • Open Firebug
  • Go to the 'console' tab

From the console you can execute javascript query's (calling functions, accessing variables etc.).

I hope this answered your question properly.

answered Jul 10, 2013 at 18:36

Comments

0

I think you are talking about Obfuscate js code

You can always de-obfuscate them

There are lots of tools availaible

Here is a addon of mozilla https://addons.mozilla.org/en-us/firefox/addon/javascript-deobfuscator/

and an online tool http://jsbeautifier.org/

answered Jul 10, 2013 at 18:39

1 Comment

In fact chrome debugger console has 'pretty-print' option to make it easier to read

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.