472,097 Members | 1,104 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,097 software developers and data experts.

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:

Expand|Select|Wrap|Line Numbers
  1. import urllib
  2. # Send a 'GET' request to protoSender
  3. data = urllib.urlencode({'LEGACY_ID' : 'work', 'BU_SOURCE_INDICATOR' : etc....})
  4. f = urllib.urlopen("http://www.blackspyraldancer.com/cardinal/protoSender.php?%s" % data)
  5. s = f.read()
Expand|Select|Wrap|Line Numbers
  1. import webbrowser 
  2. # open browser with url encoded
  3. 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 xmlRequestObjects). 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.


Aug 2 '07 #1
8 1845
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\ieexplore.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 ;)
Aug 2 '07 #2
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:
Expand|Select|Wrap|Line Numbers
  1.     function XMLResults(){
  2.       if(request.readyState == 4){
  3.         if(request.status == 200){
  4.           // var strText = request.responseText;
  5.           // document.getElementById("confirmation").innerHTML = strText;
  6.           window.open('','_parent','');
  7.           window.close();
  8.         }
  9.         else{
  10.           alert("There was a problem retrieving the XML data:\n" + reqXML.statusText);
  11.         }
  12.       }
  13.     }
I'm not sure yet if this will suffice based on performance, so I'm still open to suggestions.


Aug 2 '07 #3
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?
Aug 2 '07 #4
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.
Aug 2 '07 #5
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
Aug 2 '07 #6
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.
Aug 2 '07 #7
I'm crossing my fingers for you :)

Andelys - over and out ;)
Aug 2 '07 #8
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...
Aug 6 '07 #9

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Andrew Chalk | last post: by
3 posts views Thread by G.A. | last post: by
23 posts views Thread by Spiffy | last post: by
3 posts views Thread by Edg Bamyasi | last post: by
9 posts views Thread by Matt Helm | last post: by
1 post views Thread by mpc | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.