好的,我一天只使用Mechanize,所以要好一点:P
我想完成一个包含一个(或两个,如果可能的话)文件上传样式字段的表单.您单击的位置,它允许您浏览文件.
(我想自动将.torrent上传到私人跟踪器/网站)
现在我遇到的两个问题是在网站上没有任何表格都有名字,所以我一直在使用表格的索引来选择它们.
br.select_form(nr=4)
Run Code Online (Sandbox Code Playgroud)
现在问题是我想在提交表单时上传文件.有两个文件字段,我不认为我正确指定每个.这是使用"print br.form"制作的表格的"印刷品"
<POST http://www.###.##.##/takeupload.php multipart/form-data
<HiddenControl(MAX_FILE_SIZE=1000000) (readonly)>
<TextControl(<None>=http://www.###.##.##:81/announce.php?passkey=###) (readonly)>
<FileControl(file=<No files added>)>
<TextControl(name=)>
<SelectControl(type=[*0, 23, 22, 1, 10, 7, 12, 4, 21, 17, 18, 13, 58, 16, 15, 56, 20, 60, 5, 19, 6, 55, 57, 63, 9])>
<CheckboxControl(strip=[strip])>
<FileControl(nfo=<No files added>)>
<TextareaControl(descr=)>
<SubmitControl(<None>=Do it!) (readonly)>>
Run Code Online (Sandbox Code Playgroud)
我尝试了这段代码,希望它只是默认为第一个:
br.form.add_file(open(filename), 'text/plain', filename)
Run Code Online (Sandbox Code Playgroud)
但是,它给出了这个错误
Traceback (most recent call last):
File "script.py", line 53, in <module>
br.form.add_file(open(filename), 'text/plain', filename)
File "/usr/local/lib/python2.6/dist-packages/mechanize-0.2.4-py2.6.egg/mechanize/_form.py", line 2968, in add_file
self.find_control(name, "file", id=id, label=label, …Run Code Online (Sandbox Code Playgroud)