qq1151985918 发表于 2022-3-21 21:20:56

qiuyouzhi 发表于 2022-3-21 20:46
就是对原来的页面

刚才研究半天,requests.get 获得的源码和浏览器里的不一样


看来我是今天弄不了了,不过还是很感谢。

cflying 发表于 2022-3-21 22:01:26

看你好辛苦,帮你做一个上传图片的代码吧,返回信息中就有上传的图片名称。
import httpx
import requests
from requests_toolbelt.multipart.encoder import MultipartEncoder

headers={
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36 Edg/97.0.1072.55',
    'Content-Type':'multipart/form-data; boundary=----WebKitFormBoundaryXBU8YckJYyqg4IJ1',
    'Cookie':'PHPSESSID=6htchjqr7u8vdf8raqcmia23a1; universion-date=2022-03-21; universion=0310',
    'Host':'www.chaojibiaoge.com',
    'Origin':'https://www.chaojibiaoge.com',
    'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
    'Accept-Encoding':'gzip, deflate, br',
    'Accept-Language':'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
    'Cache-Control':'max-age=0',
    'Connection':'keep-alive',
    'Content-Length':'435624',
    }


url=r'https://www.chaojibiaoge.com/System/TableEdit/saveUploadedFile/istemp/false/modelid/undefined/fieldid/c2/recordid/null/projectid/ktjwa29p/sharekey/7ugvoaya'
#('1.jpg', open('file ', 'rb'), 'image/jpeg')

with open('11111.jpg', 'rb') as i:
    img = i.read()
    data=MultipartEncoder(
    {
    'mcssuploadfile':('11111.jpg',img, 'image/jpeg'),
    'filename':"12xx11.jpg"
    },
    boundary='----WebKitFormBoundaryXBU8YckJYyqg4IJ1'
    )
    r = requests.post(url=url,headers=headers,data=data, verify=False)
    print(r.text)

返回的代码中
<input type='text' id='uploadresult' style='display:none' value='ok:image1<=>11111.jpg~2022/03/11111_DGSsJT.jpg' /><div class='uploadresult' style='width:auto'><div style='color:green;font-size:12px'>上传成功</div></div>
value中的内容后半段就是文件名

cflying 发表于 2022-3-21 22:02:43

帮你写一段上传图片的内容
import httpx
import requests
from requests_toolbelt.multipart.encoder import MultipartEncoder

headers={
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36 Edg/97.0.1072.55',
    'Content-Type':'multipart/form-data; boundary=----WebKitFormBoundaryXBU8YckJYyqg4IJ1',
    'Cookie':'PHPSESSID=6htchjqr7u8vdf8raqcmia23a1; universion-date=2022-03-21; universion=0310',
    'Host':'www.chaojibiaoge.com',
    'Origin':'https://www.chaojibiaoge.com',
    'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
    'Accept-Encoding':'gzip, deflate, br',
    'Accept-Language':'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
    'Cache-Control':'max-age=0',
    'Connection':'keep-alive',
    'Content-Length':'435624',
    }


url=r'https://www.chaojibiaoge.com/System/TableEdit/saveUploadedFile/istemp/false/modelid/undefined/fieldid/c2/recordid/null/projectid/ktjwa29p/sharekey/7ugvoaya'
#('1.jpg', open('file ', 'rb'), 'image/jpeg')

with open('11111.jpg', 'rb') as i:
    img = i.read()
    data=MultipartEncoder(
    {
    'mcssuploadfile':('11111.jpg',img, 'image/jpeg'),
    'filename':"11111.jpg"
    },
    boundary='----WebKitFormBoundaryXBU8YckJYyqg4IJ1'
    )
    r = requests.post(url=url,headers=headers,data=data, verify=False)
    print(r.text)

cflying 发表于 2022-3-21 22:03:16

本帖最后由 cflying 于 2022-3-21 22:38 编辑

这里面最难的因该是上传图片了,上传图片的返回内容中就有图片文件名(加了随机码字符的)
得,帮你写了上传图片的代码(随手写的,里面with什么的、verify等其实也是多余的,那是抓包时加的,自己看着删就行),发个代码还要验证,发出来还要审核。。。传图片结果权限不够,我从52里传个图来。

代码中mcssuploadfile千万别删(其实改了也没啥,就是返回的代码中没有文件名而已,不改的话就有文件名,方便些),boundary别删哈,这玩意儿得和header对应,删了传不起不怪我哈
只要拿到了上传的文件名,其他参数你抓包后看着抄抄就行了,反正也简单
https://attach.52pojie.cn/forum/202203/21/220840fey7b36ky2frd3p6.png

qq1151985918 发表于 2022-3-21 23:15:27

cflying 发表于 2022-3-21 22:03
这里面最难的因该是上传图片了,上传图片的返回内容中就有图片文件名(加了随机码字符的)
得,帮你写了上 ...

我这就从被窝爬出去试试
页: 1 [2]
查看完整版本: 求助大佬,一个网页数据提交问题,貌似不是post?求指教