|
[md]
csdn 转辑中的文件是按 id 正序排序的,想改一下改为倒序排序。
写完之后,发现跟提交顺序无关,服务器总是处理为正序排序的。
所以代码白写,不过还是记录如下
* 有 input ,textarea 和 select ,要区分
* select 要注意选 checked
* imagesrc 是图片,可以不上传
传参数,要处理为 files 参数
```
post_params = dict()
for key, value in self.params.items():
post_params[key] = (None, value)
result = requests.post(url, cookies=self.cookies, files=post_params)
```
None 指文件名,后面指可读取的对象。
传参 files 调用代码如下
```
requests.api.post
requests.api.request
requests.sessions.Session#request
requests.sessions.Session#prepare_request
requests.sessions.merge_hooks
requests.models.PreparedRequest#prepare_body
requests.models.RequestEncodingMixin#_encode_files
for (k, v) in files:
# support for explicit filename
ft = None
fh = None
if isinstance(v, (tuple, list)):
if len(v) == 2:
fn, fp = v
elif len(v) == 3:
fn, fp, ft = v
else:
fn, fp, ft, fh = v
else:
fn = guess_filename(v) or k
fp = v
if isinstance(fp, (str, bytes, bytearray)):
fdata = fp
else:
fdata = fp.read()
rf = RequestField(name=k, data=fdata, filename=fn, headers=fh)
rf.make_multipart(content_type=ft)
new_fields.append(rf)
```
[/md] |
|