On 02/14/2011 01:41 PM, Karim wrote:

Hello,

As I get no response from the tutor python list, I am continuing to investigate my problem.

In fact the issue is that there are 2 forms in the interactive page and my request does nothing instead I get the interactive page not the submission I asked (query results). The 2 forms are:

   1. <FORM METHOD="POST" ACTION="/ddts/ddts_main"
      ENCTYPE="application/x-www-form-urlencoded" NAME="form1">
   2. <FORM METHOD="POST" ACTION="/ddts/ddts_main"
      ENCTYPE="application/x-www-form-urlencoded" NAME="form9">

And the parameters for each are:

1)
<INPUT TYPE="hidden" NAME="init" VALUE="">
<INPUT TYPE="hidden" NAME="LastForm" VALUE="SavedQuery">
<INPUT TYPE="hidden" NAME="NextForm" VALUE="">
<INPUT TYPE="hidden" NAME="REMOTE_USER" VALUE="karim.liateni">
<INPUT TYPE="submit" NAME="ACTION" VALUE="Query">&nbsp;
<INPUT TYPE="submit" NAME="ACTION" VALUE="Report">&nbsp;
<INPUT TYPE="submit" NAME="ACTION" VALUE="Edit">&nbsp;
<INPUT TYPE="submit" NAME="ACTION" VALUE="Delete">&nbsp;
<INPUT TYPE="submit" NAME="ACTION" VALUE="Create" ONCLICK="oncreate()">&nbsp;
<INPUT TYPE="submit" NAME="ACTION" VALUE="Create String Query">
<INPUT TYPE="hidden" NAME=".cgifields" VALUE="personalQuery">
<INPUT TYPE="hidden" NAME=".cgifields" VALUE="sharedQuery">

2)
<INPUT TYPE="hidden" NAME="LastForm" VALUE="DumpBug">
<INPUT TYPE="hidden" NAME="REMOTE_USER" VALUE="karim.liateni">
<INPUT TYPE="text" NAME="bug_id" VALUE="" SIZE=10 MAXLENGTH=10>
<INPUT TYPE="submit" NAME=".submit" VALUE="View">

And I recall my data of the progam below:

data = {
       'init' : "",
       'LastForm': "SavedQuery",
       'prompted': "yes",
       'class': "Development",
       'personalQuery': "DKPV",
       'REMOTE_USER': username,
'QS': " -p DKPVALIDATION_PLUGIN \(Class 'isequal' &quot;Development&quot; \)",
       'use_field_defs':"false",
       'QueryName': "DKPV",
       'QueryType': "personal",
       'ACTION': "Query"
       }

So the question is how could I specify the correct FORM submission and how could I chose the correct action because there are several TYPE='submit' and I am only interested by this one VALUE="Query"?

Regards
Karim

On 02/11/2011 08:51 AM, Karim wrote:

Hello,

In fact as found in the net:

"The concept of browser frames is completely outside the scope of HTTP. However, browser frames are defined in HTML, and so is the target property on form elements: &lt;form action="/somescript?x=y" method="POST" target="_top"&gt; This will make the form submit to the _top frame, which means "use the full browser window" "

That means that my post form:

<FORM METHOD="POST" ACTION="/ddts/ddts_main" ENCTYPE="application/x-www-form-urlencoded" TARGET="rightframe">

has a target property to make the submit to the 'rightframe'.

Any ideas how I can modified the code (I think the request data or whatever) below to access without knowing the temporary html file name generically.

Regards
Karim

On 02/10/2011 07:12 PM, Karim wrote:

Hello All,

I get from Steven an very useful link (void space) for http authentication. I added some codes to be able to POST FORM a query as I do it by clicking a query button to get a list of bug Id on a server. The problem is I get a html page which refers 2 frames. And I am interesting in one particular frame
namely for example,
http://{server}:{port}/wt/tmp/results:karim.liateni.31_3917.html'.format(server=server, port=port). But this pages is created every times in a tmp directory each time with a different name.

1) How can I get the name of this page because with python the page resulting of my query is not mentionned (hidden like)? Interactively there are 3 frames but only this one is of interest for me. But no name of this page is visible in the main html page.
Is there a method to get all the nested frames locations?

2) I can see this page interactively when I click on a submit query button. Do I need to add 'ACTION': "Query" <input form in the query dictionnary to simulate a click for submission (type="submit" button) ?

3) Interactively I see that cgi arg NextForm is empty so I let it like that in my query and LastForm was set to "SavedQuery". I put the
same value in my python code. Is this ok?

import urllib
import urllib2

server='dummy.com'
port='8081'

username = 'karim.liateni'
password = 'dummy_pass'

theurl = 'http://{server}:{port}/ddts/ddts_main'.format(server=server, port=port) #theurl = 'http://{server}:{port}:8081/wt/tmp/results:karim.liateni.31_3917.html'.format(server=server, port=port)

#MEMO:
#<FORM METHOD="POST" ACTION="/ddts/ddts_main" ENCTYPE="application/x-www-form-urlencoded" TARGET="rightframe">

data = {
       'NextForm': "",
       'LastForm': "SavedQuery",
       'prompted': "yes",
       'class': "Development",
       'personalQuery': "DKPV",
       'REMOTE_USER': username,
'QS': " -p DKPVALIDATION_PLUGIN \(Class 'isequal' &quot;Development&quot; \)",
       'use_field_defs':"false",
       'QueryName': "DKPV",
       'QueryType': "personal",
       'ACTION': "Query"
       }

query   = urllib.urlencode(data)
request = urllib2.Request(theurl, query)

passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, theurl, username, password)
authhandler = urllib2.HTTPBasicAuthHandler(passman)

opener = urllib2.build_opener(authhandler)
urllib2.install_opener(opener)

pagehandle = urllib2.urlopen(request)
print(pagehandle.read())
_______________________________________________
Tutor maillist  - tu...@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

_______________________________________________
Tutor maillist  - tu...@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor



The solution to handle multiple post forms in a same web page and to submit a given one programmatically is to use this very must have module ClientForm from "http://wwwsearch.sourceforge.net/ClientForm"; and maintained by John J.Lee

Example from this module:

response = urllib2.urlopen("http://wwwsearch.sourceforge.net/ClientForm/example.html";)
 forms = ClientForm.ParseResponse(response, backwards_compat=False)
 form = forms[0]
 print form

# set html widget value
form["comments"] = "Thanks, Gisle"

#Controls are html widgets (Listbox, checkbutton, combobox, etc ...)
print "parmesan" in [item.name for item in form.find_control("cheeses").items if item.selected]

# select item labelled "Mozzarella" in control with id "chz" as the same with a mouse-click:
form.find_control(id="chz").get(label="Mozzarella").selected = True

# submit the form returns a urllib2.Request object
new_request = form.click()
new_response = urllib2.urlopen(new_request)


This is a very handy and easy module!
For whom it mays concern.

Regards
Karim


-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to