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?
-
Are you running in the context of the browser? Aka open up the JS console and type the method name.epascarello– epascarello2013年07月10日 18:31:02 +00:00Commented Jul 10, 2013 at 18:31
-
I think you're just looking for the console...brbcoding– brbcoding2013年07月10日 18:31:05 +00:00Commented Jul 10, 2013 at 18:31
-
1You can install NodeJS and run Javascript without a browser.Waleed Khan– Waleed Khan2013年07月10日 18:31:53 +00:00Commented 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 clearsedavidw– sedavidw2013年07月10日 18:41:02 +00:00Commented Jul 10, 2013 at 18:41
-
are you trying to control an already opened page with python? and send commands to it?Justin L.– Justin L.2013年07月10日 18:44:02 +00:00Commented Jul 10, 2013 at 18:44
3 Answers 3
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.
Comments
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.
Comments
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/