Re: How can i find the form name without nr=0

2007-11-07 Thread John J. Lee
alex23 [EMAIL PROTECTED] writes:

 On Nov 6, 8:56 am, scripteaze [EMAIL PROTECTED] wrote:
 Is it possible then to have a form with no name and if so, how can i
 access this form

 Hey scripteaze,

 I'm not sure about mechanize, but you might have more success using
 another one of the author's modules, ClientForm: 
 http://wwwsearch.sourceforge.net/ClientForm/

 from urllib2 import urlopen
 from ClientForm import ParseResponse

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

 As it returns a list of forms, you don't need to have a name to access
 it.

mechanize forms are ClientForm forms.

Quoting from mechanize.Browser.select_form().__doc__:


Another way to select a form is to assign to the .form attribute.  The
form assigned should be one of the objects returned by the .forms()
method.


forms = list(br.forms())
br.form = pick_a_form(forms, br.global_form())


The global form (couldn't think of a better term) consists of all
form controls not contained in any FORM element.


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


Re: How can i find the form name without nr=0

2007-11-07 Thread scripteaze
On Nov 7, 1:35 pm, [EMAIL PROTECTED] (John J. Lee) wrote:
 alex23 [EMAIL PROTECTED] writes:
  On Nov 6, 8:56 am, scripteaze [EMAIL PROTECTED] wrote:
  Is it possible then to have a form with no name and if so, how can i
  access this form

  Hey scripteaze,

  I'm not sure about mechanize, but you might have more success using
  another one of the author's modules, 
  ClientForm:http://wwwsearch.sourceforge.net/ClientForm/

  from urllib2 import urlopen
  from ClientForm import ParseResponse

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

  As it returns a list of forms, you don't need to have a name to access
  it.

 mechanize forms are ClientForm forms.

 Quoting from mechanize.Browser.select_form().__doc__:

 
 Another way to select a form is to assign to the .form attribute.  The
 form assigned should be one of the objects returned by the .forms()
 method.
 

 forms = list(br.forms())
 br.form = pick_a_form(forms, br.global_form())

 The global form (couldn't think of a better term) consists of all
 form controls not contained in any FORM element.

 John- Hide quoted text -

 - Show quoted text -

Thank you guys for replying, im sure that one of these methods will
suffice, after this project, im definatly going to do more in lui of
web apps for learning..Thanks again

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


Re: How can i find the form name without nr=0

2007-11-06 Thread thebjorn
On Nov 5, 6:05 pm, scripteaze [EMAIL PROTECTED] wrote:
[...]
 Well, i wasnt sure if you could have a form without a form name, i was
 just thinking that it had one but maybe hidden and that i could
 retrieve it

I see you've got the answer you wanted already, but just for
completeness: the following is a sufficiently(*) valid form in html

  form
input type=text name=q
input type=submit
  /form

which will have a textbox, and a submit button with localized text
saying Submit Query. If you type something into the textbox and hit
the button, a GET request is sent to the same page with ?q=something
appended to the url.

You can do the same with POSTed forms:

  form method=post
input type=hidden name=cmd value=rm -rf /
input type=submit value=Erase?
  /form

in this case only a button with the text Erase? is visible.

I'm not expressing an opinion on whether this is good form wink or
not...

-- bjorn

(*) the HTML spec says that the action attribute is required, so
theoretically you must include it.

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


Re: How can i find the form name without nr=0

2007-11-05 Thread Diez B. Roggisch
scripteaze wrote:

 Im using mechanize method for retrieving the form so that i may log
 into it. I need to find a way to get the form name. Its not listed
 anywhere in the html source.The reason i need to do this is because im
 tryin not to use the for loop below. Someone told me that the form
 name should be listed in the 'print form' portion of the codes output.
 I dont believe the form name is listed there also. Any ideas/help
 would be great. Thank you in advance for your time.
 
 for form in self._br.forms():
 print form
 self._br.select_form(nr=0)
 self._br['username'] = Crawler.usrname
 self._br['password'] = line.strip()
 response=self._br.submit()
 if 'incorrect' in response.read():
 print 'password incorrect =', line.strip()

How do you expect the form to be named if there is no name given in the HTML
source?

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


Re: How can i find the form name without nr=0

2007-11-05 Thread scripteaze
On Nov 5, 8:52 am, Diez B. Roggisch [EMAIL PROTECTED] wrote:
 scripteaze wrote:
  Im using mechanize method for retrieving the form so that i may log
  into it. I need to find a way to get the form name. Its not listed
  anywhere in the html source.The reason i need to do this is because im
  tryin not to use the for loop below. Someone told me that the form
  name should be listed in the 'print form' portion of the codes output.
  I dont believe the form name is listed there also. Any ideas/help
  would be great. Thank you in advance for your time.

  for form in self._br.forms():
  print form
  self._br.select_form(nr=0)
  self._br['username'] = Crawler.usrname
  self._br['password'] = line.strip()
  response=self._br.submit()
  if 'incorrect' in response.read():
  print 'password incorrect =', line.strip()

 How do you expect the form to be named if there is no name given in the HTML
 source?

 Diez- Hide quoted text -

 - Show quoted text -

Well, i wasnt sure if you could have a form without a form name, i was
just thinking that it had one but maybe hidden and that i could
retrieve it

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


Re: How can i find the form name without nr=0

2007-11-05 Thread Diez B. Roggisch
 
 Well, i wasnt sure if you could have a form without a form name, i was
 just thinking that it had one but maybe hidden and that i could
 retrieve it

How hidden? HTML source is ... THE source. there is nothing hidden in there.

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


Re: How can i find the form name without nr=0

2007-11-05 Thread scripteaze
 b  Well, i wasnt sure if you could have a form without a form name,
i was
  just thinking that it had one but maybe hidden and that i could
  retrieve it

 How hidden? HTML source is ... THE source. there is nothing hidden in there.

Is it possible then to have a form with no name and if so, how can i
access this form

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


Re: How can i find the form name without nr=0

2007-11-05 Thread alex23
On Nov 6, 8:56 am, scripteaze [EMAIL PROTECTED] wrote:
 Is it possible then to have a form with no name and if so, how can i
 access this form

Hey scripteaze,

I'm not sure about mechanize, but you might have more success using
another one of the author's modules, ClientForm: 
http://wwwsearch.sourceforge.net/ClientForm/

from urllib2 import urlopen
from ClientForm import ParseResponse

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

As it returns a list of forms, you don't need to have a name to access
it.

Hope this helps.

-alex23

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


Re: How can i find the form name without nr=0

2007-11-05 Thread scripteaze
On Nov 5, 6:33 pm, alex23 [EMAIL PROTECTED] wrote:
 On Nov 6, 8:56 am, scripteaze [EMAIL PROTECTED] wrote:

  Is it possible then to have a form with no name and if so, how can i
  access this form

 Hey scripteaze,

 I'm not sure about mechanize, but you might have more success using
 another one of the author's modules, 
 ClientForm:http://wwwsearch.sourceforge.net/ClientForm/

 from urllib2 import urlopen
 from ClientForm import ParseResponse

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

 As it returns a list of forms, you don't need to have a name to access
 it.

 Hope this helps.

 -alex23

Thank you very much for your reply. Ill check it out.

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