File size: 2,726 Bytes
e9d6d40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
监控网络请求,看是否能捕获到 EPUB 下载请求
"""

from playwright.sync_api import sync_playwright
import time

MD5 = "d94c20d1364af9b484949659398c4062"
SLOW_URL = f"https://annas-archive.gl/slow_download/{MD5}/0/3"

def monitor_network():
    """监控网络请求"""
    print(f"目标: {SLOW_URL}\n")

    epub_requests = []
    all_requests = []

    with sync_playwright() as p:
        browser = p.chromium.launch(headless=False)
        context = browser.new_context(
            user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36",
        )
        page = context.new_page()

        # 监控请求
        def on_request(request):
            url = request.url
            if '.epub' in url.lower():
                print(f"  [EPUB请求] {url}")
                epub_requests.append(url)
            elif 'download' in url.lower() or 'file' in url.lower():
                all_requests.append(url)

        def on_response(response):
            url = response.url
            content_type = response.headers.get('content-type', '')
            if '.epub' in url.lower():
                print(f"  [EPUB响应] {url} - {content_type}")
                epub_requests.append(url)

        page.on("request", on_request)
        page.on("response", on_response)

        print("访问 slow_download...")
        page.goto(SLOW_URL, timeout=120000, wait_until="domcontentloaded")
        print(f"初始标题: {page.title()}")

        # 等待最多60秒
        for i in range(60):
            time.sleep(1)
            try:
                title = page.title()
                url = page.url

                if url.lower().endswith('.epub'):
                    print(f"\n在第{i+1}秒发现EPUB URL: {url}")
                    browser.close()
                    return url

                if title != "DDoS-Guard":
                    print(f"\n在第{i+1}秒: 标题={title}, URL={url}")

                if (i + 1) % 15 == 0:
                    print(f"  {i+1}秒... 标题={title}")
            except Exception as e:
                print(f"  {i+1}秒... (导航中)")
                continue

        print(f"\n最终URL: {page.url}")
        print(f"\n捕获到的EPUB相关请求: {epub_requests}")
        print(f"捕获到的下载相关请求: {all_requests[:5]}")

        browser.close()
        return epub_requests[0] if epub_requests else None

if __name__ == "__main__":
    print("=" * 60)
    print("监控网络请求")
    print("=" * 60)
    result = monitor_network()
    if result:
        print(f"\n成功: {result}")
    else:
        print("\n未捕获到EPUB请求")