user2255757
user2255757

Reputation: 766

Python: Mechanize select_form returns nothing

When trying to use the mechanize i seem to be unable to use select_form(id) to retrieve the form even though there is an object generator in forms().

code:

import mechanize

urls = ['http://stackoverflow.com/']

for url in urls:
    print url
    br = mechanize.Browser()
    br.addheaders = [('User-Agent', 'Firefox')]
    br.open(url)

    for form in br.forms():
        print form
    print br.select_form(nr=0)

output:

http://stackoverflow.com/
<GET http://stackoverflow.com/search application/x-www-form-urlencoded
  <TextControl(q=)>>
None

Upvotes: 1

Views: 442

Answers (1)

alecxe
alecxe

Reputation: 473803

It actually selects the form, since it does not return any errors.

The reason you see None printed is that select_form() returns you None.


As a separate note, why don't use StackExchange API instead of browsing with mechanize?

Upvotes: 2

Related Questions