From 550a77b1050475464c90b4d03d89d7b74f03e985 Mon Sep 17 00:00:00 2001 From: zhangwen Date: Mon, 9 Mar 2026 09:08:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xhs/image_up.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/xhs/image_up.py b/xhs/image_up.py index a9eece5..c19b799 100644 --- a/xhs/image_up.py +++ b/xhs/image_up.py @@ -22,7 +22,9 @@ def get_x_s(url, data=None): if u.query != "": result += "?" + u.query if data: - result += json.dumps(data, ensure_ascii=False) + if type(data) == dict: + data = json.dumps(data, ensure_ascii=False) + result += data x_s = eval_js.call('xhs_x_s', result) return x_s @@ -136,15 +138,15 @@ def put_data(fileid, token): print('-------------', res) -def new(file_id): +def new(file_id, title, connect): url = "https://edith.xiaohongshu.com/web_api/sns/v2/note" data = { "common": { "type": "normal", "note_id": "", "source": "{\"type\":\"web\",\"ids\":\"\",\"extraInfo\":\"{\\\"subType\\\":\\\"official\\\",\\\"systemId\\\":\\\"web\\\"}\"}", - "title": "11", - "desc": "22", + "title": title, + "desc": connect, "ats": [], "hash_tag": [], "business_binds": "{\"version\":1,\"noteId\":0,\"bizType\":0,\"noteOrderBind\":{},\"notePostTiming\":{},\"noteCollectionBind\":{\"id\":\"\"},\"noteSketchCollectionBind\":{\"id\":\"\"},\"coProduceBind\":{\"enable\":true},\"noteCopyBind\":{\"copyable\":true},\"interactionPermissionBind\":{\"commentPermission\":0},\"optionRelationList\":[]}", @@ -179,13 +181,13 @@ def new(file_id): "video_info": None } # data_raw = '{"common":{"type":"normal","note_id":"","source":"{\\"type\\":\\"web\\",\\"ids\\":\\"\\",\\"extraInfo\\":\\"{\\\\\\"subType\\\\\\":\\\\\\"official\\\\\\",\\\\\\"systemId\\\\\\":\\\\\\"web\\\\\\"}\\"}","title":"111","desc":"222","ats":[],"hash_tag":[],"business_binds":"{\\"version\\":1,\\"noteId\\":0,\\"bizType\\":0,\\"noteOrderBind\\":{},\\"notePostTiming\\":{},\\"noteCollectionBind\\":{\\"id\\":\\"\\"},\\"noteSketchCollectionBind\\":{\\"id\\":\\"\\"},\\"coProduceBind\\":{\\"enable\\":true},\\"noteCopyBind\\":{\\"copyable\\":true},\\"interactionPermissionBind\\":{\\"commentPermission\\":0},\\"optionRelationList\\":[]}","privacy_info":{"op_type":1,"type":0,"user_ids":[]},"goods_info":{},"biz_relations":[],"capa_trace_info":{"contextJson":"{\\"recommend_title\\":{\\"recommend_title_id\\":\\"\\",\\"is_use\\":3,\\"used_index\\":-1},\\"recommendTitle\\":[],\\"recommend_topics\\":{\\"used\\":[]}}"}},"image_info":{"images":[{"file_id":"spectrum/KLpGPJCvUHX1KUGCjYgq2pG_pgnnovE6c-1snNb8CKYNOo8","width":3024,"height":4032,"metadata":{"source":-1},"stickers":{"version":2,"floating":[]},"extra_info_json":"{\\"mimeType\\":\\"image/png\\",\\"image_metadata\\":{\\"bg_color\\":\\"\\",\\"origin_size\\":1745.205078125}}"}]},"video_info":null}' - + data = json.dumps(data, ensure_ascii=False) headers = get_headers(cookies, url, data) - response = requests.post(url, headers=headers, cookies=cookies, json=data) + headers["Content-Type"] = "application/json;charset=UTF-8" + response = requests.post(url, headers=headers, cookies=cookies, data=data.encode("utf-8")) print(response.text) - # def get_file_url(): # url = "https://www.xiaohongshu.com/web_api/sns/v5/creator/file/encryption?file_id=%2Fspectrum%2FQfyQUONtYxXAxO16o8dxSipox7U8UonPCJu9hvYHLq5AjrI&type=image&ts=1772869510861&sign=0f37b5816f1a65c43087554236326cf3" # response = requests.get(url, headers=get_headers(cookies,url,), cookies=cookies, params=params) @@ -199,7 +201,7 @@ def run(): fileid = file['data']['uploadTempPermits'][0]['fileIds'][0] token = file['data']['uploadTempPermits'][0]['token'] put_data(fileid, token) - new(fileid) + new(fileid, '我是标题', '内容内容') if __name__ == '__main__':