Python を使用してこのフォームに入力したい:
<form method="post" enctype="multipart/form-data" id="uploadimage">
<input type="file" name="image" id="image" />
<input type="submit" name="button" id="button" value="Upload File" class="inputbuttons" />
<input name="newimage" type="hidden" id="image" value="1" />
<input name="path" type="hidden" id="imagepath" value="/var/www/httpdocs/images/" />
</form>
ご覧のとおり、まったく同じ名前の 2 つのパラメーターがあるため、Mechanize を使用してそれを行うと、次のようになります。
import mechanize
br = mechanize.Browser()
br.open('www.site.tld/upload.php')
br.select_form(nr=0)
br.form['image'] = '/home/user/Desktop/image.jpg'
br.submit()
エラーが発生しています:
mechanize._form.AmbiguityError: more than one control matching name 'image'
インターネット (このサイトを含む) で見つけたすべての解決策は機能しませんでした。別のアプローチはありますか?残念ながら、HTML フォームの入力の名前を変更することはできません。
前もって感謝します。