urllib supports javascript

J

J. Peng

hello,

Which useragent lib supports javascript?
I know something about these libs: urllib,urllib2,cookielib,httplib
But I'm not sure which one of them can support javascript scripts.
Thanks!
 
M

M¨¦ta-MCI \(MVP\)

Hi!

"javascript support" need more details:
- only the (abstract) language?
- or, also, visuals aspects?


On Windows, you can use,easily, the language (JScript). Example:

import win32com.client
js=win32com.client.Dispatch('ScriptControl')
js.language='jscript'

src="""function jmul2(x){
r=(x++)*2;
return r;
}
"""
js.addcode(src)
print js.eval("jmul2(111);") # => 222


This simple example show how define & use a function in Javascript code.
By the same way, you can mixer javascript, perlscript, vbscript,
rubyscript, phpscript, etc.


Now, for the visual aspect of the question, you must work differently.
On way is to work in HTA (HTml Application). Inside HTA, there are a
"simili-browser", able to render HTML code, and run Javascript &
Pythonscript (a bit different from PythonC).

Here un example:

<hta:application
windowstate="normal"
caption="no"
singleinstance="yes"
/>
<html>
<head>
<script language=Python>

def Init():
self.resizeTo(360,360)
self.moveTo(110,10)

def meteo(num):
obj = document.getElementById('METEODIV')
st = '<a href="http://ponx.org/ponx/guie.htm"><img
src="http://meteo.region-nord.com/webmestre/prev/j'+num+'.jpg"
alt="prevision meteo" style="border:none"> </a>'
obj.innerHTML = st

</script>
</head>

<body bgColor=#FFFFFF background="" scroll=no onload="Init();">
<FORM>
&nbsp;&nbsp;
<input ID="bt1" name="bt1" type="button" style="width:100px"
VALUE="Aujourd'hui" onmousedown="meteo('1')" />
<input ID="bt2" name="bt2" type="button" style="width:100px"
VALUE="Demain" onmousedown="meteo('2')" />
<input ID="bt3" name="bt3" type="button" style="width:100px"
VALUE="Apr¨¨s-Demain" onmousedown="meteo('3')" /><br>

<blockquote>
<DIV id="METEODIV">MMEETTEEOO</DIV>
</blockquote>
</FORM>

<script language=Python>
meteo('1')
</script>

</body>
</html>


Warning: ActiveScripting must be authorized (inside IE)



Another way is to drive Interne-Explorer from Python. it's possible to
call (& return) Javascript functions & code, from Python, with
parameter.
It's more complicated, but with more possibilities. For PLUIE, it's the
way which I chose.


@-salutations

Michel Claveau
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top