jeudi 28 janvier 2016

Mechanize Python library

I've recently started working with mechanize in python to fill forms.

br = mechanize.Browser()
retorno = br.open("http://ift.tt/1JKwtEN")
nomes = ['Subject A', 'Subject B','Subject C']
email = '********'

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


br.form['nome[]'] = 'Subject A'
br.form['email'] = email
br.submit()

The problem is that I would like to enter all the names in the 'nomes' in the 'nome[]' field, but it only accepts one string at the time. When you enter the website, there is a "plus" button that adds more fields to enter other names. I would like to know if there is a way to acess this button using the script or to enter the names using a kind of list or dictionary.

Also, I would like to know if I could iterate on the 'idEvento' array, since each one is a different form.

Here are the forms:

<TextControl(nome[]=)>
<TextControl(email=)>
<SelectControl(idEvento=[335, 334, *336])>

Here are the controls of the form

text nome[] 
email email 
select idEvento ['336']
submit None 

Thanks!




Aucun commentaire:

Enregistrer un commentaire