import os, requests, random
exit
image_path = r"F:\pythondemo\images"
image_list = os.listdir(image_path)
uploadUrl = 'https://upload.cnblogs.com/imageuploader/processupload?host=www.cnblogs.com'
file_path = r""
user_agent_list = [
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/22.0.1207.1 Safari/537.1" \
"Mozilla/5.0 (X11; CrOS i686 2268.111.0) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11", \
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.6 (KHTML, like Gecko) Chrome/20.0.1092.0 Safari/536.6", \
"Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.6 (KHTML, like Gecko) Chrome/20.0.1090.0 Safari/536.6", \
"Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/19.77.34.5 Safari/537.1", \
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.9 Safari/536.5", \
"Mozilla/5.0 (Windows NT 6.0) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.36 Safari/536.5", \
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1063.0 Safari/536.3", \
"Mozilla/5.0 (Windows NT 5.1) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1063.0 Safari/536.3", \
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_0) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1063.0 Safari/536.3", \
"Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1062.0 Safari/536.3", \
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1062.0 Safari/536.3", \
"Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1061.1 Safari/536.3", \
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1061.1 Safari/536.3", \
"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1061.1 Safari/536.3", \
"Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1061.0 Safari/536.3", \
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.24 (KHTML, like Gecko) Chrome/19.0.1055.1 Safari/535.24", \
"Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/535.24 (KHTML, like Gecko) Chrome/19.0.1055.1 Safari/535.24"
]
headers = {
"user-agen": random.choice(user_agent_list),
# "cookie": "Hm_lvt_eaa57ca47dacb4ad4f5a257001a3457c=1638099737,1638352729,1640343416,1640352956; _ga_4CQQXWHK3C=GS1.1.1650864859.1.0.1650864861.0; __gads=ID=9f79e2351ee824c3:T=1650870368:S=ALNI_MYi_3EL5zcrMtAfznrnPkus13bc9g; _gid=GA1.2.1023219083.1656944428; __gpi=UID=0000050351db1cc3:T=1650870368:RT=1656944428:S=ALNI_MYI8X-X0vt5V0J55WSHmYrRCNNJOQ; .Cnblogs.AspNetCore.Cookies=CfDJ8EOBBtWq0dNFoDS-ZHPSe50B1HRi_1uU75LQh47eCQLOxr6OPwrc6hAElpg0_7hUF-smo8NYNwfMV7bCNWFr-R98FRJjcbyePSsIIN69ljJYHyNkMiKoGz0wsn-0aOsEuwF8YDQT_sXVheGCEEd1GkcPPPHT8ML4Ez1KTZYHF4PfAJU9vUwnkDep1wLPlpnC0NhNNBIDLyUETphsOiAymHKW0h4bD8eVsOhsdKdiaEFwgF4R6UGN4anYXoqrmp0krCFpdfOOs1NYW3muYBmlt3Vwk3w9ZQAX1bd-8tgzZj678ng7vr25rQ5OW_xw_tPZs6k08xY93smUx2ZGar4JcDhOozMZYONphioc3rSOhGteHGWj-ydM1I6SLD0cAI2HZaXWRqj_LUYJUdZJrMtYniYOeJ8DH-Al-kIBTDZBBl5hW3KxNZwl3DJ77GFCAfDiJwDKC7O8tEtLqYiRak9JhhzBt1PQQB3c7mq2eu2eRlYFpyHrD5w3U48Gpg5yT_Rm-1AdDlJe7-yirKKZH4axflCNvd09v1-FLqtCh8_kawDZKNf_6WNBl4iD_CgQYI1LgQ; .CNBlogsCookie=C780161738DC0E24F9477C3E9E70ED2919C4629D43685A71EB2F45DC4784C690E3F428009531BBED6586138636B80C8FFD0605C16EA8E21CE94A9C8D4E837D80C209B234E57129D9A01826C5C9A1DA476C4F01C5; _ga_3Q0DVSGN10=GS1.1.1656944429.1.1.1656944452.37; _ga=GA1.2.328792840.1615731898; Hm_lvt_866c9be12d4a814454792b1fd0fed295=1656944427,1656949679; .AspNetCore.Antiforgery.b8-pDmTq1XM=CfDJ8EOBBtWq0dNFoDS-ZHPSe53ZiBt17nG2NXMA5cXXN068EsE-Ath-ZaBu3YoIzNzbiaLYTUnuXxvUnXt1cUZFj2VA795sUAMuJZR2LI41wvLxBb4kghedFcEWTHZ-ZFd6nuMhF7skaQv9p__dttbboHg; _gat_gtag_UA_48445196_1=1; Hm_lpvt_866c9be12d4a814454792b1fd0fed295=1656949956; _gat_gtag_UA_476124_1=1",
# "user-agent":'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Mobile Safari/537.36'
}
def get_ip_pool():
url = 'http://api.shenlongip.com/ip'
res = requests.get(url=url).json()
print(res)
def get_url():
with open("./test.md", mode="r", encoding="utf-8") as f:
file_list = f.readlines()
for image_url in file_list:
for image in image_list:
if len(image) == len(image_url[-1:-20:-1]) and image in image_url:
new_url = upload(os.path.join(image_path, image))
title, _ = image_url.split("(")
url = title + "(" + new_url + ")"
image_url = image_url.replace(image_url, url)
# print("image_url", image_url)
with open("./nvim.md", mode='a', encoding="utf-8") as f1:
f1.write(image_url)
print("%s:写入完成"% image_url )
def upload(image_path):
format = image_path.split(".")[-1]
file = [
("",("fileName", open(image_path, "rb"),"image/"+format))
]
response = requests.post(uploadUrl,headers = headers,files = file).json()
image_url = response.get("message")
return image_url
get_ip_pool()