문제

다음 스크립트를 실행할 때 :

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

나는 얻다: ValueError : 값 속성은 Readonly입니다

추가 할 때 여전히 같은 오류가 발생합니다.

br.form.set_all_readonly(False)

그렇다면 Python Mechanize를 사용하여 HTML 양식과 상호 작용하여 파일을 업로드 할 수 있습니까?

리차드

도움이 되었습니까?

해결책

이것은 기계화로 올바르게 수행하는 방법입니다.

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

다른 팁

twill 구축되었습니다 mechanize 스크립팅 웹 형태를 산들 바람으로 만듭니다. 보다 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.

>>> 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top