urllib supports javascript

Discussion in 'Python' started by J. Peng, Feb 2, 2008.

  1. J. Peng

    J. Peng Guest

    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!
    J. Peng, Feb 2, 2008
    #1
    1. Advertising

  2. 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
    M¨¦ta-MCI \(MVP\), Feb 2, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. js
    Replies:
    0
    Views:
    480
  2. J. Peng

    Re: urllib supports javascript

    J. Peng, Feb 2, 2008, in forum: Python
    Replies:
    0
    Views:
    395
    J. Peng
    Feb 2, 2008
  3. Jonathan Gardner

    Asynchronous urllib (urllib+asyncore)?

    Jonathan Gardner, Feb 26, 2008, in forum: Python
    Replies:
    1
    Views:
    458
    Terry Jones
    Feb 27, 2008
  4. Chris McDonald
    Replies:
    0
    Views:
    266
    Chris McDonald
    Nov 1, 2010
  5. wylbur37
    Replies:
    5
    Views:
    96
    Thomas 'PointedEars' Lahn
    Jan 11, 2004
Loading...

Share This Page