当我运行以下脚本时:
from mechanize import Browser
br = Browser()
br.open(url)
br.select_form(name="edit_form")
br['file'] = 'file.txt'
br.submit()
我得到:ValueError: value attribute is readonly
添加时仍然出现同样的错误:
br.form.set_all_readonly(False)
那么,我如何使用 Python Mechanize 与 HTML 表单交互以上传文件?
理查德
最佳答案
这是使用 Mechanize 正确执行此操作的方法:
br.form.add_file(open(filename), 'text/plain', filename)
关于python - 使用 Python Mechanize 上传文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1299855/