473,395 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

How can i find the form name without "nr=0"

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()
this is the output of 'print form'
--------------------------------------------------------
<POST https://somesite.com/login.html application/x-www-form-
urlencoded
<TextControl(username=)>
<PasswordControl(password=)>
<SubmitControl(<None>=Secure Login) (readonly)>
<HiddenControl(dest=inbox.ws) (readonly)>>

Nov 5 '07 #1
9 6928
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
Nov 5 '07 #2
On Nov 5, 8:52 am, "Diez B. Roggisch" <de...@nospam.web.dewrote:
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

Nov 5 '07 #3
>
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
Nov 5 '07 #4
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

Nov 5 '07 #5
On Nov 6, 8:56 am, scripteaze <scripte...@gmail.comwrote:
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

Nov 6 '07 #6
On Nov 5, 6:33 pm, alex23 <wuwe...@gmail.comwrote:
On Nov 6, 8:56 am, scripteaze <scripte...@gmail.comwrote:
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.

Nov 6 '07 #7
On Nov 5, 6:05 pm, scripteaze <scripte...@gmail.comwrote:
[...]
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 <winkor
not...

-- bjorn

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

Nov 6 '07 #8
alex23 <wu*****@gmail.comwrites:
On Nov 6, 8:56 am, scripteaze <scripte...@gmail.comwrote:
>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
Nov 7 '07 #9
On Nov 7, 1:35 pm, j...@pobox.com (John J. Lee) wrote:
alex23 <wuwe...@gmail.comwrites:
On Nov 6, 8:56 am, scripteaze <scripte...@gmail.comwrote:
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

Nov 8 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Mason A. Clark | last post by:
LAST WORD(s): 1. MSIE6 and Firefox will go to the top of the page on command <a href="#top">go upsy</a> even if there is NO name="top" or id="top" They know what a "top" is :-) Opera...
3
by: davidkarlsson74 | last post by:
Error: document.getElementById("folderMenu").cells has no properties File: http://www.volkswagen.se/tillbehor/js/foldermenu.js Rad: 49 The function activates different DIV:s, but doesn't seem to...
4
by: Xiphias | last post by:
Hi, Hope you can help me on this... I got 1 form with a sub form. On this subform there are only parts of records, so you can select the one you want to edit. When you dubbel click that...
40
by: aku | last post by:
I'm looking for the absolute fastest way to count the nr of bits that are set to "1" in a string. Presumably I then first need the fastest way to do this in a byte. I think this is it, but...
2
by: Guoqi zheng | last post by:
Dear sir, I am using the default paging function of datagrid. Below is my code. <PagerStyle NextPageText="&gt;&gt;&gt;" PrevPageText="&lt;&lt;&lt;" HorizontalAlign="Center" Mode="NumericPages"></PagerStyle> ...
10
by: roy.anderson | last post by:
Error is thus: "Cast from type 'DBNull' to type 'String' is not valid." Simple, right? Well, no (or at least not for me). Here's a function, followed by the calling code below: Function...
0
by: AA Arens | last post by:
I made a find record button on my form "company" (with field for name, phone nr, e-mail etc.). I expect that when I focus on one of the field, the "look in" of the find-record dialog box should...
23
by: Abhi | last post by:
Hi.. I wanted the C source code in machine readable format for the book "Numerical Recipes in C". I got hold of the pdf version of the book somehow. Does anyone have the complete C code of the...
14
by: terrible.theterrible4 | last post by:
Hello w3c,php, fedora + apache experts! Is there code I can use for POST A COMMENT? I am not ready for PHP yet. Anybody did it in JS?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.