Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.python
urllib supports javascript
J. Peng
2/2/2008 2:07:00 AM
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!
1 Answer
M?ta-MCI \(MVP\)
2/2/2008 2:46:00 PM
0
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"&...
src="
http://meteo.region-nord.com/webmestre/prev/j'+num+'...
alt="prevision meteo" style="border:none"> </a>'
obj.innerHTML = st
</script>
</head>
<body bgColor=#FFFFFF background="" scroll=no onload="Init();">
<FORM>
<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
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
urllib supports javascript
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password