running a web page from python

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SimonJ621
    New Member
    • Aug 2007
    • 12

    #1

    running a web page from python

    Hi all,

    I have an python application that I would like to use to send some data to a web page. I am sending this data via url encoding to pass some variables to the page. While I can get the server side to process the data on the web page I'm sending data to, I can't get the javascript to execute. Here are the two things I have tried:

    A)
    Code:
    import urllib
    # Send a 'GET' request to protoSender
    data = urllib.urlencode({'LEGACY_ID' : 'work', 'BU_SOURCE_INDICATOR' : etc....})
    f = urllib.urlopen("http://www.blackspyraldancer.com/cardinal/protoSender.php?%s" % data)
    s = f.read()
    B)
    Code:
    import webbrowser 
    # open browser with url encoded
    webbrowser.open("http://localhost/protosender.php?LEGACY_ID=1111&BU_SOURCE_INDICATOR=9999&etc....", new=0)

    The problem with A is that the client side javascript doesn't run (which is used to send some xmlRequestObjec ts). I realize this is because the browser isn't launched and therefore not available to run the javascript.

    B opens a browser and runs the page correctly, but it won't open the site in the same browser window (despite what it's supposed to do). Because this application will be running many many times, I wouldn't be able to keep opening new browsers windows.

    I would appreciate any help. Thank you.

    Jason


    -------------------------------------------------------------------
    http://www.elefoo.com/
    http://www.blackspyral dancer.com/
  • Andelys
    New Member
    • Aug 2007
    • 47

    #2
    I can see your problem... But is it necessary to execute javascript? because that would be very hard to get it work (i'm talking about example A).

    In example B, maybe you could make you program open a browser like "C:\Program Files\Internet Explorer\ieexpl ore.exe [url]", and then after a amount of time it will close it... I don't know how you can make that, and i dont know if its possible, just a idea :)

    Andelys over and out ;)

    Comment

    • SimonJ621
      New Member
      • Aug 2007
      • 12

      #3
      Thanks for the reply and suggestion. My temporary solution (very similar to your suggestion) is to run window.close when the xml http response comes back. The code looks like this:
      Code:
          function XMLResults(){
            if(request.readyState == 4){
              if(request.status == 200){
                // var strText = request.responseText;
                // document.getElementById("confirmation").innerHTML = strText;
                window.open('','_parent','');
                window.close();
              }
              else{
                alert("There was a problem retrieving the XML data:\n" + reqXML.statusText);
              }
            }
          }
      I'm not sure yet if this will suffice based on performance, so I'm still open to suggestions.

      Thanks,
      Jason

      -----------------------------------------------------------
      http://www.elefoo.com/
      http://www.blackspyral dancer.com/

      Comment

      • Andelys
        New Member
        • Aug 2007
        • 47

        #4
        You could do that, but if it's your homepage, then why do you have to run javascript? could you recode that so it doesn't have to use javascript?

        Comment

        • SimonJ621
          New Member
          • Aug 2007
          • 12

          #5
          Well... there really isn't a homepage in this application. I am using a browser to send an http xml request, but I'm calling that browser from another program (Business Objects Data Quality). This is to build a prototype to test how some data reacts to the same transforms that are being used in an earlier project, not the actual process flow. This page will be requested about 10,000 times from Business Objects in a only a few minutes. We'll see if the computer crashes when I test it :).

          We already have another Java solution that converts a delimited flat file written by Business Objects into XML for further downstream activities. This is merely to see if such a solution is feasible.

          Comment

          • Andelys
            New Member
            • Aug 2007
            • 47

            #6
            I'm pretty sure that it will lack or crash. It's also a dirty solution.

            But, tell me if it work :D just PM me

            Comment

            • SimonJ621
              New Member
              • Aug 2007
              • 12

              #7
              Dirty, yes... I'm just curious at this point what happens. It's been a while since I've been able to crash a system :) I'll PM you the results when I test it.

              Comment

              • Andelys
                New Member
                • Aug 2007
                • 47

                #8
                I'm crossing my fingers for you :)

                Andelys - over and out ;)

                Comment

                • eric dexter
                  New Member
                  • Sep 2006
                  • 46

                  #9
                  autoit can be used as a com object If you are using windows that may be a good answer or to use internet explorer as a com object.. sendkeys is also another library that could be helpfull to send key press's to a program...

                  Comment

                  Working...