By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,551 Members | 1,159 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,551 IT Pros & Developers. It's quick & easy.

running a web page from python

SimonJ621
P: 12
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)
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()
B)
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.

Jason


-------------------------------------------------------------------
http://www.elefoo.com/
http://www.blackspyraldancer.com/
Aug 2 '07 #1
Share this Question
Share on Google+
8 Replies


P: 47
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

SimonJ621
P: 12
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.

Thanks,
Jason

-----------------------------------------------------------
http://www.elefoo.com/
http://www.blackspyraldancer.com/
Aug 2 '07 #3

P: 47
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

SimonJ621
P: 12
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

P: 47
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

SimonJ621
P: 12
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

P: 47
I'm crossing my fingers for you :)

Andelys - over and out ;)
Aug 2 '07 #8

P: 46
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.