[color=]壹伴
收费模板 用于微信公众号文章
需要打开编辑器的HTML代码模式粘贴进去~~~
程序下载链接: https://pan.baidu.com/s/1hSQROL_clIZgZ03Ycvw3sA?pwd=52pj 提取码: 52pj 复制这段内容后打开百度网盘手机App,操作更方便哦
蓝奏:https://wwvg.lanzoub.com/b00wmxph0b 密码:52pj
本页是照抄的论坛大神的帖子:https://www.52pojie.cn/forum.php ... 79156&highlight=135,相比135,壹伴这个没办法直接提取,用浏览器加载完了再提取的,所以比135提取器慢。
4.0版本 使用庸世俗人罢勒大神的api,速度很快
[Python] 纯文本查看 复制代码import tkinter as tk
from tkinter import messagebox
import threading
import requests
import json
from bs4 import BeautifulSoup
def get_yiban_template_api(template_id):
"""通过模板API获取壹伴模板的HTML代码"""
try:
# 构建模板API URL
url = f"https://yiban.io/api/style_template/system/one?style_template_id={template_id}"
# 设置请求头
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
'Accept': 'application/json, text/plain, */*',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
'Referer': 'https://yiban.io/',
'Origin': 'https://yiban.io'
}
# 发送请求
response = requests.get(url, headers=headers, timeout=10)
response.raise_for_status()
# 直接解析JSON响应
data = json.loads(response.text)
if not data.get('success'):
raise ValueError(f"模板API请求失败: {data.get('status_message', '未知错误')}")
# 直接获取total字段(包含完整HTML内容)
html_code = data['style_template']['total']
if not html_code:
raise ValueError("模板详情为空")
return html_code
except requests.exceptions.RequestException as e:
raise ValueError(f"网络请求失败: {str(e)}")
except json.JSONDecodeError as e:
raise ValueError(f"JSON解析失败: {str(e)}")
except Exception as e:
raise ValueError(f"获取模板失败: {str(e)}")
def get_yiban_style_api(style_id):
"""通过样式API获取壹伴样式中心的HTML代码"""
try:
# 构建样式API URL
url = f"https://yiban.io/api/article_editor/material/one?material_id={style_id}"
# 设置请求头
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
'Accept': 'application/json, text/plain, */*',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
'Referer': 'https://yiban.io/',
'Origin': 'https://yiban.io'
}
# 发送请求
response = requests.get(url, headers=headers, timeout=10)
response.raise_for_status()
# 直接解析JSON响应
data = json.loads(response.text)
if not data.get('success'):
raise ValueError(f"样式API请求失败: {data.get('status_message', '未知错误')}")
# 直接获取detail字段(包含HTML内容)
html_code = data['material']['detail']
if not html_code:
raise ValueError("素材详情为空")
# 使用BeautifulSoup解析HTML
soup = BeautifulSoup(html_code, 'html.parser')
# 查找第一个包含实际内容的section
sections = soup.find_all('section')
for section in sections:
# 跳过空的段落section
if (section.get('data-role') == 'paragraph' and
(not section.get_text(strip=True) or section.get_text(strip=True) == '')):
continue
# 检查section是否包含实际内容
if (section.get('style') or
section.find('img') or
section.get_text(strip=True) or
section.get('data-id')):
return str(section)
# 如果没找到合适的section,返回整个detail内容
return html_code
except requests.exceptions.RequestException as e:
raise ValueError(f"网络请求失败: {str(e)}")
except json.JSONDecodeError as e:
raise ValueError(f"JSON解析失败: {str(e)}")
except Exception as e:
raise ValueError(f"获取样式失败: {str(e)}")
def get_yiban_style(style_id):
"""智能获取壹伴样式/模板的HTML代码"""
# 首先尝试模板API
try:
print(f"尝试使用模板API获取ID: {style_id}")
return get_yiban_template_api(style_id)
except Exception as e:
print(f"模板API失败: {str(e)}")
# 如果模板API失败,尝试样式API
try:
print(f"尝试使用样式API获取ID: {style_id}")
return get_yiban_style_api(style_id)
except Exception as e2:
print(f"样式API也失败: {str(e2)}")
raise ValueError(f"无法获取ID为 {style_id} 的内容,请检查ID是否正确")
def extract_style():
"""提取样式"""
style_id = str_TextBox1.get().strip()
if not style_id:
messagebox.showwarning('提示', '请输入样式ID')
return
# 禁用按钮
extract_button.config(text='提取中...', state=tk.DISABLED)
def extract_thread():
try:
# 获取样式
style_html = get_yiban_style(style_id)
# 复制到剪贴板
win.clipboard_clear()
win.clipboard_append(style_html)
# 显示成功消息
win.after(0, lambda: messagebox.showinfo('提示', '已复制到你的粘贴板,直接粘贴即可~'))
except Exception as e:
# 显示错误
win.after(0, lambda: messagebox.showinfo('提示', f'样式ID错误~无法获取数据~~\n{str(e)}'))
finally:
# 恢复按钮状态
win.after(0, lambda: extract_button.config(text='提取模板', state=tk.NORMAL))
# 在后台线程中执行
thread = threading.Thread(target=extract_thread, daemon=True)
thread.start()
# 创建主窗口
win = tk.Tk()
win.geometry('310x88+50+50')
win.title('壹伴样式提取助手')
# 创建标签
ihLabel1 = tk.Label(win, text='输入样式ID', font=('宋体', '9'))
ihLabel1.place(x=7, y=14, height=22)
# 创建输入框
str_TextBox1 = tk.StringVar() # 绑定变量
ihTextBox1 = tk.Entry(win, textvariable=str_TextBox1, font=('宋体', '9'))
ihTextBox1.place(x=79, y=7, width=101, height=29)
str_TextBox1.set('24190') # 设置默认值
# 创建按钮
extract_button = tk.Button(win, text='提取模板', font=('宋体', '9'), command=extract_style)
extract_button.place(x=202, y=7, width=88, height=29)
# 绑定回车键
ihTextBox1.bind('', lambda event: extract_style())
# 设置焦点
ihTextBox1.focus()
win.mainloop()