惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google Online Security Blog
Google Online Security Blog
博客园_首页
酷 壳 – CoolShell
酷 壳 – CoolShell
Jina AI
Jina AI
博客园 - Franky
大猫的无限游戏
大猫的无限游戏
Hugging Face - Blog
Hugging Face - Blog
博客园 - 司徒正美
V
V2EX
雷峰网
雷峰网
云风的 BLOG
云风的 BLOG
V
Visual Studio Blog
F
Full Disclosure
Y
Y Combinator Blog
V
V2EX - 技术
Attack and Defense Labs
Attack and Defense Labs
S
Security @ Cisco Blogs
Schneier on Security
Schneier on Security
Microsoft Azure Blog
Microsoft Azure Blog
SecWiki News
SecWiki News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
The GitHub Blog
The GitHub Blog
量子位
PCI Perspectives
PCI Perspectives
S
Secure Thoughts
D
Darknet – Hacking Tools, Hacker News & Cyber Security
AWS News Blog
AWS News Blog
Blog — PlanetScale
Blog — PlanetScale
爱范儿
爱范儿
K
Kaspersky official blog
B
Blog
A
Arctic Wolf
Hacker News: Ask HN
Hacker News: Ask HN
L
LangChain Blog
T
Tor Project blog
P
Privacy & Cybersecurity Law Blog
Recent Announcements
Recent Announcements
宝玉的分享
宝玉的分享
The Register - Security
The Register - Security
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
L
Lohrmann on Cybersecurity
D
Docker
A
About on SuperTechFans
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Google DeepMind News
Google DeepMind News
The Last Watchdog
The Last Watchdog
S
Security Affairs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Privacy International News Feed
Simon Willison's Weblog
Simon Willison's Weblog

蜗居

安全编码规范单元测试报告(最终版) - 学习笔记 – 蜗居 不用GPU、每秒处理100页、零API费用——开源工具轻松提取PDF数据 - 汪洋大海 – 蜗居 AI Agent终于有系统教材了:微软这18课深度拆解 - 汪洋大海 – 蜗居 free-claude-code 让Claude Code真的免费用起来 - 汪洋大海 – 蜗居 最新开源帮你写PPT的Skill “guizang-ppt-skill” 完整拆解 - 汪洋大海 – 蜗居 精选 Skills 推荐:10 个让 Coding Agent 如虎添翼的Skills + 优质来源分享 Skill deep-article: 深度分析文章写作助手 - 学习笔记 – 蜗居 深度文章写作prompt_v2 - 学习笔记 – 蜗居 会议纪要整理 Prompt v2 - 学习笔记 – 蜗居
DMIT 指定商品库存监控脚本(Playwright 版) - 学习笔记 – 蜗居
版权声明:本站原创文章,由gdd发表在学习笔记分类下,于2026年04月17日最后更新 转载请注明:DMIT 指定商品库存监控脚 · 2026-04-17 · via 蜗居

A-A+

【注意:此文章为博主原创文章!转载需注意,请带原文链接,至少也要是txt格式!】

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env python3
"""
DMIT 商品库存监控脚本(Playwright 版)
每 360 秒检测一次,仅有货时发通知
"""
 
import time
import subprocess
import sys
from datetime import datetime
 
# ── 配置 ──────────────────────────────────────────
URL = "https://woj.app/url.php?id=186" ##这里是参考https://woj.app/9698.html 这里的VPS产品进行购买
CHECK_INTERVAL = 360  # 检查间隔(秒)
 
OUT_OF_STOCK_KEYWORDS = [
    "out of stock",
    "currently unavailable",
    "no longer available",
    "out-of-stock",
    "product is out of stock",
    "product is not available",
]
# ──────────────────────────────────────────────────
 
 
def notify(title: str, message: str, sound: str = "Glass") -> None:
    script = f'display notification "{message}" with title "{title}" sound name "{sound}"'
    subprocess.run(["osascript", "-e", script])
 
 
def check_stock() -> tuple[bool, str]:
    from playwright.sync_api import sync_playwright
 
    with sync_playwright() as p:
        browser = p.chromium.launch(headless=True)
        context = browser.new_context(
            user_agent=(
                "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) "
                "AppleWebKit/537.36 (KHTML, like Gecko) "
                "Chrome/124.0.0.0 Safari/537.36"
            )
        )
        page = context.new_page()
        try:
            resp = page.goto(URL, wait_until="domcontentloaded", timeout=30000)
            if resp and resp.status == 404:
                return False, "页面不存在(404)"
 
            page.wait_for_timeout(3000)
            html = page.content().lower()
 
            for keyword in OUT_OF_STOCK_KEYWORDS:
                if keyword in html:
                    return False, "缺货"
 
            if (
                page.query_selector('input[name="a"][value="add"]') or
                page.query_selector(".order-button") or
                "configoptions" in html or
                "orderbutton" in html or
                "add to cart" in html
            ):
                return True, "有货"
 
            return False, "状态未知"
 
        except Exception as e:
            return False, f"异常: {e}"
        finally:
            browser.close()
 
 
def main():
    try:
        import playwright  # noqa
    except ImportError:
        print("❌ 未安装 playwright,请先执行:")
        print("   pip3 install playwright")
        print("   python3 -m playwright install chromium")
        sys.exit(1)
 
    print(f" 开始监控: {URL}")
    print(f"⏱  检查间隔: {CHECK_INTERVAL} 秒")
    print("按 Ctrl+C 停止\n")
 
    while True:
        now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        in_stock, status = check_stock()
 
        if in_stock:
            print(f"[{now}] ✅ {status}")
            notify(" DMIT 有货啦!", "pid=186 现在可以购买!快去下单!", sound="Glass")
        else:
            # 缺货/异常只打日志,不发通知
            print(f"[{now}] ❌ {status}")
 
        try:
            time.sleep(CHECK_INTERVAL)
        except KeyboardInterrupt:
            print("\n已停止监控")
            sys.exit(0)
 
 
if __name__ == "__main__":
    try:
        main()
    except KeyboardInterrupt:
        print("\n已停止监控")