根据:https://developers.weixin.qq.com/doc/offiaccount/Draft_Box/Add_draft.html,
例如说content我简单设置成:
<p>line 1</p>
<p><br></p>
<p>line 2</p>
(line1和line2之间只空1行)
上传后其content html会变成:
<p>line 1</p>
<p> <br></p>
<p>line 2</p>
系统会自动加入 这样就变成line1和line2之间空了两行
请问如何设置,系统才不会自动加入 ? 我需要的是我设置的content模板是什么,系统就上传什么。谢谢!
你好,请问具体哪里有添加nsbp
图1:原html文件,
图2:上传微信后台后,草稿会自动添加空行。(请注意,这里没有壹伴插件)
类似的排版问题,之前有其他用户有反馈过,似乎也没有得到解决。(搜索排版,有好几个帖子反馈,以下只列出其中一个)
https://developers.weixin.qq.com/community/develop/doc/0004caa9b305b0e33d9de046d5b800?highLine=%25E5%25BE%25AE%25E4%25BF%25A1%25E4%25BC%2597%25E5%25A8%25B1%25E8%2587%25B3%25E5%25B0%258A%25E7%2589%259B%25E5%25BB%25BA%25E7%25BE%25A4%25E6%2589%25BE%25E8%25B0%2581%25E6%258B%25BF%25E6%2588%25BF%25E5%258D%25A1%25E3%2580%2590%25E2%2595%2585%25E8%2596%2587%25EF%25BC%259B11511989
希望可以重视一下这个问题。谢谢
你好 我是用壹伴的插件查看html, 如上图所示。不只是上面的html, 如果用其它的html我也会遇到类似的上传到草稿后系统帮我添加html的问题。
以下是我的代码:
#html content <p>line 1 </p> <p> <br> </p> <p>line 2 </p> _--------------------------------------------------------------------- import requests import json import os # Set up environment os.environ['no_proxy'] = '*' # ====================Config==========================# # Personal access token and bot ID personal_access_token = 'xxx' bot_id = 'xxx' # Query string query = "1" # Number of times to repeat the request repeat_time = 3 # Draft API URL Template (replace ACCESS_TOKEN with actual token) draft_api_url_template = "https://api.weixin.qq.com/cgi-bin/draft/add?access_token={access_token}" # html_file_path = r'D:\sjuvi\Documents\5.公众号开发\03.公众号正文图片\html_template\xiegang_template.html' html_file_path = r'C:\Users\sjuvi\Desktop\weixin_test\test2.html' # ====================Config==========================# # Read the content of the HTML file with open(html_file_path, 'r', encoding='utf-8') as file: html_content = file.read() # Article details with the extracted HTML content articles = [ { "title": "中文标题", # Chinese title "content": html_content, "thumb_media_id": "PdEzMawG529MXCtwub53gRYEoq6kuxaaQwa0HuVwrURiqiZTBjkpvrzlFEj4cfs2", # "pic_crop_235_1":"0_0_1_0.5236", "pic_crop_1_1":"0.04_0_0.4655_1", } ] # Define the URL and headers for the first API call url = 'https://api.coze.cn/open_api/v2/chat' headers = { 'Authorization': f'Bearer {personal_access_token}', 'Content-Type': 'application/json; charset=utf-8', # Ensure UTF-8 encoding 'Accept': '*/*', 'Host': 'api.coze.cn', 'Connection': 'keep-alive', } # Define the request payload data = { "conversation_id": "123", "bot_id": bot_id, "user": "123333333", "query": f'{query}', "stream": False } # Convert the payload to JSON with ensure_ascii=False to preserve Chinese characters json_data = json.dumps(data, ensure_ascii=False) # Send the POST request to retrieve the access code response = requests.post(url, headers=headers, data=json_data.encode('utf-8')) # Encode in UTF-8 # Check if the request was successful if response.status_code == 200: # Parse the response as JSON response_json = response.json() # Extract the 'content' field where the access code is nested content_str = response_json['messages'][0]['content'] # Parse the nested JSON in the 'content' field content_json = json.loads(content_str) # Extract the access code from the 'output' field access_code = content_json['output'] print(f'Extracted Access Code: {access_code}') # Now use the access_code to make the POST request to add the draft draft_api_url = draft_api_url_template.format(access_token=access_code) # Define the request payload for the draft API draft_payload = { "articles": articles } # Convert the draft payload to JSON with ensure_ascii=False to preserve Chinese characters draft_json_data = json.dumps(draft_payload, ensure_ascii=False) # Send the POST request to add the draft draft_response = requests.post(draft_api_url, headers=headers, data=draft_json_data.encode('utf-8')) if draft_response.status_code == 200: draft_response_json = draft_response.json() print(f'Draft API Response: {draft_response_json}') else: print(f'Failed to add draft. Status Code: {draft_response.status_code}') else: print(f'Failed to get a valid response for access code. Status Code: {response.status_code}')