Executing Javascript, then reading value

Melih Onvural melih.onvural at gmail.com
Mon Jan 29 15:44:07 EST 2007


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




More information about the Python-list mailing list