Seite 1 von 1

mechanize und Upload

Verfasst: Freitag 8. August 2008, 23:52
von Crazed
Hey,
1. Ja habe ich den Thread ein paar unter diesem Thread gesehen wo es um ein änhliches Thema ging. Dort wurde unter anderem mechanize erwähnt ("oder noch besser mechanize").

Jetzt wollte ich das mal wirklich austesten:

Code: Alles auswählen

In [1]: import mechanize

In [2]: br = mechanize.Browser()

In [3]: br.open('http://www.imagebanana.com/')
Out[3]: <response_seek_wrapper at 0x8694dcc whose wrapped object = <closeable_response at 0x8694bec whose fp = <socket._fileobject object at 0x868d9cc>>>

In [4]: for form in br.forms():
   ...:     print form
   ...:     
   ...:     
<POST http://www.imagebanana.com/ multipart/form-data
  <FileControl(img=<No files added>)>
  <SubmitControl(send=Hochladen!) (readonly)>
  <CheckboxControl(check_thumbnail=[on])>
  <SelectControl(resize=[80x80, 100x75, 100x100, 150x112, x1, *320x240, 450x338, 540x1024, 640x480, 800x600, 1024x768, 1280x1024, 1600x1200, x2, 640x480, 800x600, 1024x768, 1280x1024, 1400x1050, 1600x120, 1920x1200, x3, 853x480, 720x576, 1024x576, 1280x720, 1920x1080])>>

In [5]: br.select_form(nr=0)

In [6]: br['img'] = '/home/crackpod/test.jpg'
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)

/home/crackpod/<ipython console> in <module>()

/usr/lib/python2.5/site-packages/ClientForm-0.2.9-py2.5.egg/ClientForm.py in __setitem__(self, name, value)
   2878             control.value = value
   2879         except AttributeError, e:
-> 2880             raise ValueError(str(e))
   2881 
   2882     def get_value(self,

ValueError: value attribute is readonly
Hat jemand eine Idee wie man dem Feld trotzdem einen Wert zuweisen kann? Ich meine es ist auf der Seite "read-only" ja, aber wenn man reinklickt bekommt man ein Filewizard um die Datei anzuwählen - aber das scheint mit mechanize nicht zu gehen, oder?

MfG,
CracKPod

PS: Tut mir Leid das ich schon wieder nerve ^^...

Verfasst: Samstag 9. August 2008, 00:01
von BlackVivi
br.form.add_file wäre vllt eine Idee =D

Verfasst: Samstag 9. August 2008, 00:04
von Crazed
Argh *tot umfall*...

Danke ViVi ^^!