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!
None of them do. Javascript support is a very complex task! I believe
there have been efforts to harness the spidermonkey code base [1] but
they date back to Python 2.3.
It may be that the IronPython environment has more to offer, especially
now that DLR support is specifically intended to promote interaction and
information exchange between code in different languages, but that is
oure speculation on my part.
regards
Steve
[1]: http://wwwsearch.sourceforge.net/python-spidermonkey/
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
[1] http://pamie.sourceforge.net/
On Feb 2, 2008 11:07 AM, J. Peng <jp...@block.duxieweb.com> wrote:
> 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!
Ok thanks.
I'm running the script on linux host (commands line mode),so can't run a
X-mode browser.
I'm familiar with WWW::Mechanize but this famous Perl module also
doesn't support a JS plugin,though there is someone else has developed
that a plugin.
"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>
<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