Question

Quand je lance le script suivant:

from mechanize import Browser
br = Browser()
br.open(url)
br.select_form(name="edit_form")
br['file'] = 'file.txt'
br.submit()

J'obtenir: ValueError: attribut de valeur est en lecture seule

Et je reçois toujours la même erreur quand j'ajoute:

br.form.set_all_readonly(False)

Alors, comment puis-je utiliser Python Mechanize pour interagir avec un formulaire HTML pour télécharger un fichier?

Richard

Était-ce utile?

La solution

Voici comment le faire correctement avec Mechanize:

br.form.add_file(open(filename), 'text/plain', filename)

Autres conseils

twill est construit sur mechanize et fait forme web de script un jeu d'enfant. Voir python-www-macro .

>>> from twill import commands
>>> print commands.formfile.__doc__

>> formfile <form> <field> <filename> [ <content_type> ]

Upload a file via an "upload file" form field.

>>> 
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top