百家号,作为百度的内容发布平台,不仅为创作者提供了一个展示和分享知识的空间,还意外地成为了一个免费的图床选择。用户可以通过本工具上传图片到百家号中,并获取图片链接,从而在其他平台上使用这些图片。
使用步骤
1、打开百家号按F12-网络-复制Cookie
2、粘贴cookie上传图片
3、复制URL
Python代码
import tkinter as tk
from tkinter import filedialog
import requests
import urllib3
import pyperclip
import base64
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
def upload_image():
url = "aHR0cHM6Ly9iYWlqaWFoYW8uYmFpZHUuY29tL3BjdWkvcGljdHVyZS91cGxvYWQ="
url = base64.b64decode(url).decode("utf-8")
print(url)
custom_cookie = cookie_entry.get(
"1.0", tk.END
).strip()
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36 Edg/99.0.1150.30",
"Cookie": custom_cookie,
}
file_path = filedialog.askopenfilename()
files = {"media": open(file_path, "rb")}
response = requests.post(url, headers=headers, files=files)
if response.status_code == 200:
data = response.json()
url = data["ret"]["https_url"]
result_label.config(text="上传成功,图片链接为:" + url)
copy_button.config(state=tk.NORMAL)
global success_url
success_url = url
else:
result_label.config(text="上传失败,错误信息为:" + response.text)
def copy_url_to_clipboard():
pyperclip.copy(success_url)
result_label.config(text="已复制到剪贴板")
# 创建GUI窗口
root = tk.Tk()
root.title("百家号变图床 - By wkdxz")
root.geometry("370x150")
window_width = root.winfo_reqwidth()
window_height = root.winfo_reqheight()
position_right = int(root.winfo_screenwidth() / 2 - window_width / 2)
position_down = int(root.winfo_screenheight() / 2 - window_height / 2)
root.geometry("+{}+{}".format(position_right, position_down))
cookie_label = tk.Label(
root, text="输入Cookie(登录百家号,然后按F12拿Cookie,不会就搜索)"
)
cookie_label.pack()
cookie_entry = tk.Text(root, height=4, width=50)
cookie_entry.pack()
button_frame = tk.Frame(root)
button_frame.pack()
upload_button = tk.Button(button_frame, text="上传图片", command=upload_image)
upload_button.pack(side=tk.LEFT, padx=10, pady=5)
copy_button = tk.Button(
button_frame, text="复制URL", command=copy_url_to_clipboard, state=tk.DISABLED
) # 初始状态为禁用
copy_button.pack(side=tk.LEFT, padx=10, pady=5)
result_label = tk.Label(root, text="")
result_label.pack()
root.mainloop()
1. 本站资源皆来自互联网收集。
2. 如有侵权或不妥之处的资源,请联系我们,将在第一时间删除。
3. 联系邮箱:admin#58zi.com(#换成@)
评论(0)