python脚本上传Markdown图片
1.首先在windows主机上配置java环境(前面)
2.本地上传markdown图片
3.对应的python脚本
import requests
import json
from sys import argv
uploadUrl = 'https://upload.cnblogs.com/imageuploader/processupload?host=www.cnblogs.com'
headers = {
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36",
"cookie": "Hm_lvt_3bd1186294082ae40e916fa6d7689203=1593417608; gr_user_id=aaa7191e-bb1a-46d9-be2e-ff276024847c; grwng_uid=97901908-e8db-46a0-91c2-60fb28c6d16c; Hm_lvt_851cdd44d7a836d43196b0bfa8c0c3bb=1598582328; Hm_lvt_39b794a97f47c65b6b2e4e1741dcba38=1601462181,1601529451,1601557931,1601612293; __utmz=226521935.1603176570.1.1.utmcsr=cn.bing.com|utmccn=(referral)|utmcmd=referral|utmcct=/; UM_distinctid=175da962071c0-0b8ffc5a4661f1-930346c-1fa400-175da9620727b9; __utma=226521935.1457895727.1589698044.1603176569.1606027830.2; __gads=ID=814762e0d2d90c71:T=1608295830:R:S=ALNI_MYq5E7JXwars34J0tN8ha65yQwxPg; _ga_4CQQXWHK3C=GS1.1.1609575453.4.0.1609575456.0; _ga=GA1.2.1457895727.1589698044; Hm_lvt_d63b8784bb79994299b3dd2563c1cd31=1610031370; Hm_lvt_d8d668bc92ee885787caab7ba4aa77ec=1610432628; sc_is_visitor_unique=rx12123033.1612322984.738683687A554FFAFD48B491F4152F54.1.1.1.1.1.1.1.1.1-10500913.1606024404.1.1.1.1.1.1.1.1.1; _gid=GA1.2.511897680.1614776086; .Cnblogs.AspNetCore.Cookies=CfDJ8EklyHYHyB5Oj4onWtxTnxbScfS2LpKaRru0A1tuPqMs8i4Oo3f4N8agxVRIZV6uqK5lzjGJqI3gMrwA4W3bRpwLF6qmb6iONka8IR3qsfAQLGDkjg0NMjYzSFpbLb9AbYGsUY3vMeOMaSJQVy_Ods885CGcC_BJseFtR-ovok5m7jjgBOLiyGZzltJVnHl_UrawJeA7MgSiQ1rqzonhjdJKsESdD4QFrOZbKjINNCKyYQ44R9dv-4fw4HJXAJZ5z0jtOxfCkD8zUFQZ5OcQ2GMSUQZU_8WCJWPI3GlQ6Yoa_d8BXv88ZBrCzRJ6V1LmUluroMg9JNq_E8oRmrf91pb4fW9-T_tRM-iuCjBTpGMl9-yM3MRRR2wMU3WlyP325QOr_5_Q3fSoe485aI1ra_ULCusohy1b0wRys8XnOaVGaAPuFPt1poDrpAXaEQ75pctpZahsN00hqqruvgH4W9NSOkNGj0usrgm7n7fDA685J8iZZAqD2Eb-H6rmmEdZepIlwHSXNJu1fVaEE1itdv8yWov4apzm1M-jvsOr8r1n7wduyfHuJnHKccpV1E-gBQ; .CNBlogsCookie=B4817C43BABF69C461D5C293CB0648F5CCDA36FD2149EA01B6AD6A65556E2ED885366E652034691650536E796EF3C24CA0FECFB15B8F97D4361E02B0C7CFB1B961D6E93C3B64C7A39A50F1E70057186F3E0D3374; .AspNetCore.Session=CfDJ8EklyHYHyB5Oj4onWtxTnxYalmxbmqvXSYfBjW9yjacsrwaYgnJ4dSKe79oZzGFHi44dSJ1B4m7xv8%2BwRITpb7DpmuqzZGNFf0cQb13YN%2FLTb92hvB69xIuwsh%2FqPngpVvpdI%2B%2B%2FiuZqef6n4N%2FrwFZMJxxJCTZ%2BklrjDZTBixS9; _gat_gtag_UA_48445196_1=1" # 自己的cookie
}
# 类型映射
mimeMapping = {".png": 'image/png', '.gif': 'image/gif', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg'}
for i in argv[1:]:
# 图片地址参数
imgPath = i
# 对应的mime
mime = imgPath[imgPath.rindex("."):]
file = [
("",("fileName", open(imgPath, "rb"), mimeMapping[mime]))
]
response = requests.post(uploadUrl,headers = headers,files = file)
data = json.loads(response.text)
print(data['message'])
4验证图片上传结果
5.结果入图所示
6.上传图片
格式-------图像---------上传所有本地图片