473,322 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Executing Javascript, then reading value

I need to execute some javascript and then read the value as part of a
program that I am writing. I am currently doing something like this:

import htmllib, urllib, formatter

class myparser(htmllib.HTMLParser):
insave = 0
def start_div(self, attrs):
for i in attrs:
if i[0] == "id" and i[1] == "pr":
self.save_bgn()
self.insave = 1

def end_div(self):
if self.insave == 1:
print self.save_end()
self.insave = 0

parser = myparser(formatter.NullFormatter())

#def getPageRank(self, url):
try:
learn_url = "http://127.0.0.1/research/getPageRank.html?q=http://
www.yahoo.com&"
pr_url = urllib.urlopen(learn_url)
parser.feed(pr_url.read())
except IOError, e:
print e

but the result is the javascript function and not the calculated
value. Is there anyway to get the javascript to execute first, and
then return to me the value? thanks in advance,

Melih Onvural

Jan 29 '07 #1
6 3554
Thanks, let me check out this route, and then I'll post the results.

Melih Onvural

On Jan 29, 4:04 pm, Jean-Paul Calderone <exar...@divmod.comwrote:
On 29 Jan 2007 12:44:07 -0800, Melih Onvural <melih.onvu...@gmail.comwrote:
I need to execute some javascript and then read the value as part of a
program that I am writing. I am currently doing something like this:Python doesn't include a JavaScript runtime. You might look into the
stand-alone Spidermonkey runtime. However, it lacks the DOM APIs, so
it may not be able to run the JavaScript you are interested in running.
There are a couple other JavaScript runtimes available, at least. If
Spidermonkey is not suitable, you might look into one of them.

Jean-Paul
Jan 29 '07 #2
Melih Onvural schrieb:
I need to execute some javascript and then read the value as part of a
program that I am writing. I am currently doing something like this:

import htmllib, urllib, formatter

class myparser(htmllib.HTMLParser):
insave = 0
def start_div(self, attrs):
for i in attrs:
if i[0] == "id" and i[1] == "pr":
self.save_bgn()
self.insave = 1

def end_div(self):
if self.insave == 1:
print self.save_end()
self.insave = 0

parser = myparser(formatter.NullFormatter())

#def getPageRank(self, url):
try:
learn_url = "http://127.0.0.1/research/getPageRank.html?q=http://
www.yahoo.com&"
pr_url = urllib.urlopen(learn_url)
parser.feed(pr_url.read())
except IOError, e:
print e

but the result is the javascript function and not the calculated
value. Is there anyway to get the javascript to execute first, and
then return to me the value? thanks in advance,
Do it in a browser. There are ways to automate one, for example the
webbrowser module, and others.

Then rework your script to work with AJAX.

Diez
Jan 30 '07 #3
Jean-Paul Calderone:
You might look into the
stand-alone Spidermonkey runtime. However, it lacks the DOM APIs, so
it may not be able to run the JavaScript you are interested in running.
There are a couple other JavaScript runtimes available, at least.
This may be okay too:
http://www.digitalmars.com/dscript/

Bye,
bearophile

Jan 30 '07 #4
Melih Onvural wrote:
Thanks, let me check out this route, and then I'll post the results.

Melih Onvural

On Jan 29, 4:04 pm, Jean-Paul Calderone <exar...@divmod.comwrote:
>On 29 Jan 2007 12:44:07 -0800, Melih Onvural <melih.onvu...@gmail.com>
wrote:

>>I need to execute some javascript and then read the value as part of a
program that I am writing. I am currently doing something like
this:Python doesn't include a JavaScript runtime. You might look into
the

stand-alone Spidermonkey runtime. However, it lacks the DOM APIs, so it
may not be able to run the JavaScript you are interested in running. There
are a couple other JavaScript runtimes available, at least. If
Spidermonkey is not suitable, you might look into one of them.
This is getting to be a common problem. One used to be able to
look at web pages from a program by reading the HTML. Now you need to
load the page into a browser-like environment, run at least the
OnLoad JavaScript, and then start looking at the document object module.
This requires a browser emulator, a browser without a renderer.
Useful for spam filters and such.

It's not clear if the original poster needs that much capability,
though.

John Nagle
Jan 30 '07 #5
In fact what you're describing is exactly what I needed. I ended up
finding a way to execute the javascript using Rhino and then capturing
the
result. Not exactly what I wanted to do, but once I found it out, it
works.

Melih Onvural

On Jan 30, 2:57 pm, John Nagle <n...@animats.comwrote:
Melih Onvural wrote:
Thanks, let me check out this route, and then I'll post the results.
Melih Onvural
On Jan 29, 4:04 pm, Jean-Paul Calderone <exar...@divmod.comwrote:
On 29 Jan 2007 12:44:07 -0800, Melih Onvural <melih.onvu...@gmail.com>
wrote:
>I need to execute some javascript and then read the value as part of a
program that I am writing. I am currently doing something like
this:Python doesn't include a JavaScript runtime. You might look into
the
stand-alone Spidermonkey runtime. However, it lacks the DOM APIs, so it
may not be able to run the JavaScript you are interested in running. There
are a couple other JavaScript runtimes available, at least. If
Spidermonkey is not suitable, you might look into one of them.

This is getting to be a common problem. One used to be able to
look at web pages from a program by reading the HTML. Now you need to
load the page into a browser-like environment, run at least the
OnLoad JavaScript, and then start looking at the document object module.
This requires a browser emulator, a browser without a renderer.
Useful for spam filters and such.

It's not clear if the original poster needs that much capability,
though.

John Nagle

Jan 31 '07 #6

MelihIn fact what you're describing is exactly what I needed. I ended
Melihup finding a way to execute the javascript using Rhino and then
Melihcapturing the result. Not exactly what I wanted to do, but once I
Melihfound it out, it works.

There is an embeddable C implementation as well: SpiderMonkey. It has both
a core engine and a standalone app. There also appears to a an unmaintained
Python interface: python-spidermonkey. Relevant URLs:

http://www.mozilla.org/js/spidermonkey/
http://cheeseshop.python.org/pypi/python-spidermonkey/

Skip
Jan 31 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Michael | last post by:
I am reading and setting a cookie using JavaScript in the BODY onload and onunload events respectively. This works fine. However when I use ASP to set the cookie under some condition where I...
8
by: alanstew | last post by:
With the body tag calling out 'window onload', a function with a 'window.open' fails at the 'window.open' line. If I cut out the body tag, the function executes as normal. At first I thought it...
29
by: Mic | last post by:
Goal: delay execution of form submit Code (Javascript + JScript ASP): <% Response.Write("<OBJECT ID='IntraLaunch' STYLE='display : none' WIDTH=0 HEIGHT=0...
20
by: JulioHM | last post by:
Hello, Not sure if this is the right discussion group to post this, but here it goes. For some god-forsaken reason (which I can't find out either) MSIE stopped executing any JavaScripts. In...
1
by: den2005 | last post by:
Hi everybody, I am confused and still looking why this codes is not working. Can anyone notice or know why this code is not working? Thanks in advance. Code working: <form id="form1"...
3
by: Kirk | last post by:
Let me start by saying that I am a complete idiot when it comes to JS. However, I need help with something that apparently can only be done this way. I am using an ASP.NET AJAX control...
3
by: sjohnson1984 | last post by:
Hello all, thanks for taking the time out to read this. I have a javascript function, the purpose of which is to compare 2 form values and redirect the user if two values are met - however,...
7
by: robin1983 | last post by:
Hi, good morning everyone, i have a file called attendence.php The problem is that some part of code is executing properly and half of the code is not and i dont get any warning or error message. For...
6
by: cantrell78 | last post by:
I can't for the life of me figure out how to execute javascript inside of div that was set using innerHTML or in my case using cloneNode and replaceChild (not my idea to do this, I'm just fixing...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.