吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 6472|回复: 44
上一主题 下一主题
收起左侧

[Python 原创] 分享小小辅助工具,提取壹伴收费模板 用于微信公众号文章

  [复制链接]
跳转到指定楼层
楼主
congcongzhidao 发表于 2025-8-27 17:05 回帖奖励
本帖最后由 congcongzhidao 于 2025-8-28 18:13 编辑

小小辅助工具,提取壹伴收费模板 用于微信公众号文章
需要打开编辑器的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('<Return>', lambda event: extract_style())

# 设置焦点
ihTextBox1.focus()

win.mainloop() 

免费评分

参与人数 10吾爱币 +11 热心值 +8 收起 理由
gaoqiao2018 + 1 热心回复!
木鱼水心 + 1 + 1 谢谢@Thanks!
人时地事 + 1 我很赞同!666666666
priteat + 1 + 1 我很赞同!
xlln + 1 + 1 我很赞同!
jnct + 1 谢谢@Thanks!
yanglinman + 1 谢谢@Thanks!
Shengkissyou + 1 + 1 谢谢@Thanks!
hrh123 + 4 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
忘情的城市 + 1 + 1 谢谢@Thanks!

查看全部评分

本帖被以下淘专辑推荐:

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

推荐
庸世俗人罢勒 发表于 2025-8-28 00:33
我之前也写了一部分,只不过是拿的json直接取出代码来用

元素用的:https://yiban.io/api/article_editor/material/one?material_id={}
[Python] 纯文本查看 复制代码
data = json.loads(response.text)
            ……
            html_code = data['material']['detail']

            ……
模板用的:https://yiban.io/api/style_template/system/one?style_template_id={}
           
[Python] 纯文本查看 复制代码
……
html_code = data['style_template']['total']
……



各平台的搞成了一个大杂烩

免费评分

参与人数 5吾爱币 +5 热心值 +5 收起 理由
dmg127113 + 1 + 1 我很赞同!
S.trail + 1 + 1 可以请求大佬分享一下吗,真的很感谢
石原里美 + 1 + 1 可以分享么~!
wjbg2022 + 1 + 1 用心讨论,共获提升!
congcongzhidao + 1 + 1 我很赞同!

查看全部评分

推荐
 楼主| congcongzhidao 发表于 2025-8-28 08:45 |楼主
知心 发表于 2025-8-27 23:14
报错提示啥,看这个源码应该得下载chrome_driver配合使用

已经使用webdriver-manager自动管理ChromeDriver
4#
ZGBSQX 发表于 2025-8-27 17:50
5#
 楼主| congcongzhidao 发表于 2025-8-27 17:52 |楼主
ZGBSQX 发表于 2025-8-27 17:50
完全不行,随便一个id:24297

<section data-mid="" style="width: 100%;padding: 0 11px 0 19px;"><section data-mid="" style="width: 100%;display: flex;flex-direction: column;"><section data-mid="" nodeleaf="" style="width: 23px;display: flex;justify-content: center;align-items: center;z-index: 1;margin: 0 0 -16px -17px;"><img alt="" data-mid="" src="https://wximg.yiban.io/img_proxy?src=http://mmbiz.qpic.cn/mmbiz_png/cr9YyS063QrVstianyX9gPA4EZicfkbyKdBQyPtQHPwSLJePicuZmXcBiaLaRSTWrY6UibPpAaeNxLjOSiaeHaSvdHMg/0?from=appmsg" style="display: block;"/></section><section data-mid="" nodeleaf="" style="width: 48px;display: flex;justify-content: center;align-items: center;z-index: 1;align-self: flex-end;margin: 0 22px 3px 0;"><img alt="" data-mid="" src="https://wximg.yiban.io/img_proxy?src=http://mmbiz.qpic.cn/mmbiz_gif/CGEwnc7DGPkXwCkjLX8HzCgjKO1KuxPTWw8L9BNNTM3b8WVfHQxV3vIibDycqksck67KWnnVu75ctUZFfpde2kw/0?from=appmsg" style="display: block;"/></section><section data-mid="" style="outline: 1px solid #8CC4FF;width: 100%;"><section data-mid="" style="width: 100%;text-align: left;background: #EAF3FF;padding: 7px 12px 6px 12px;transform: translate(-5px, -5px);"><p data-mid="" style="font-size: 14px;color: #323232;line-height: 28px;word-break: break-word;" yb-mpa-mark="mark-style-text">别致的设计,赋予这款汽车无可比拟的美感。流线型车身,豪华内饰,每一个细节都彰显出精致与品质。这不仅是一辆汽车,更是艺术与科技的完美结合。</p></section></section><section data-mid="" nodeleaf="" style="width: 10px;display: flex;justify-content: center;align-items: center;z-index: 1;align-self: flex-end;margin: -3px -3px 0 0;"><img alt="" data-mid="" src="https://wximg.yiban.io/img_proxy?src=http://mmbiz.qpic.cn/sz_mmbiz_png/66Px0lScLmhsSQ81eCsVKJ3rdZkSvWiajhKcPGVl5T8wjtDrfJwp0JOA6IpdLIBVawKV3q1zsXaOP95lR6Gm0zg/0?from=appmsg" style="display: block;"/></section></section></section>
6#
 楼主| congcongzhidao 发表于 2025-8-27 17:53 |楼主
ZGBSQX 发表于 2025-8-27 17:50
完全不行,随便一个id:24297

是win7系统吗,我win10和win11都测试没问题
7#
忘情的城市 发表于 2025-8-27 21:14
这个好,非常感谢,明天试试效果,96、秀米能行吗
8#
MylogosXx 发表于 2025-8-27 22:25

感谢大佬。学习一下
9#
知心 发表于 2025-8-27 23:14
ZGBSQX 发表于 2025-8-27 17:50
完全不行,随便一个id:24297

报错提示啥,看这个源码应该得下载chrome_driver配合使用
10#
fengjixy 发表于 2025-8-27 23:45
楼主的这个真的很实用,开过壹伴、秀米、135会员,有些太贵了。
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - 52pojie.cn ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2026-5-17 04:02

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表