<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">'''
    use playwright to open https://app.zikanalytics.com/login
    set input#email value to s.h.01@hotmail.de,
    set input #password to !gREwEKC5M#u!
    then submit
'''
from playwright.sync_api import sync_playwright
import sys
import json
import re
import os

global authorization

def handle_response(response):
    if response.request.resource_type == "xhr" or response.request.resource_type == "fetch":
        try:
            result = {}
            match=re.search(r'TrendingeBayNiches|TrendingeBaySeller|TrendingProducts', response.url)
            if match:
                data = response.json()
                result[match.group()] = json.dumps(data, indent=2)
                if result:
                    # print(result)
                    json_dir = os.path.abspath(os.path.join(os.getcwd(), '../../public/json'))
                    print("JSON Directory:", json_dir)

                    # Ø¥Ù†Ø´Ø§Ø¡ Ø§Ù„Ù…Ø¬Ù„Ø¯ Ø¥Ø°Ø§ Ù„Ù… ÙŠÙƒÙ† Ù…ÙˆØ¬ÙˆØ¯Ù‹Ø§
                    os.makedirs(json_dir, exist_ok=True)
                    if match:
                        file_path = os.path.join(json_dir, f"{match.group()}.json")

                        with open(file_path, 'w') as f:
                            json.dump(data, f, indent=2)

                        print(f"Data saved to: {file_path}")

        except:
            pass


def on_url_change(url, frame):
    if(url == 'https://app.zikanalytics.com/dashboard'):
        print(f"URL changed to: {url}")

def main():
    try:
        with sync_playwright() as p:
            # Launch browser
            browser = p.chromium.launch(headless=False)
            context = browser.new_context()
            page = context.new_page()

            def intercept_request(request):
                headers = request.headers
                # print(headers)
                if "authorization" in headers:
                    print("Authorization Header:", headers["authorization"])

                    if headers["authorization"]:  # Ø§Ù„ØªØ£ÙƒØ¯ Ø£Ù† Ø§Ù„ØªÙˆÙƒÙ† Ù„ÙŠØ³ ÙØ§Ø±ØºÙ‹Ø§
                        url = "https://api.zikanalytics.com/DashboardInsight/TrendingeBaySeller?selling=ebay.com&amp;businessModel=dropshipping&amp;sourceProduct=amazon.com&amp;productSource=NONE"
                        authorization_token = headers["authorization"]  # Ø§Ø³ØªØ®Ø±Ø§Ø¬ Ø§Ù„ØªÙˆÙƒÙ†



                            # Ø§Ø³ØªØ®Ø¯Ø§Ù… old-school AJAX Ù…Ø¹ XMLHttpRequest
                        result = page.evaluate(f"""
                            (async () =&gt; {{
                                return new Promise((resolve) =&gt; {{
                                    var xhr = new XMLHttpRequest();
                                    xhr.open("GET", "{url}", true);
                                    xhr.setRequestHeader("Authorization", "{authorization_token}");
                                    xhr.setRequestHeader("Content-Type", "application/json");

                                    xhr.onreadystatechange = function () {{
                                        if (xhr.readyState == 4) {{
                                            resolve(xhr.responseText);
                                        }}
                                    }};

                                    xhr.send();
                                }});
                            }})();
                        """)

                        print("Response Data:\n", result)



            page.on('framenavigated', lambda frame: on_url_change(frame.url, frame))

            context.on("request", intercept_request)

            # Navigate to login page
            page.goto('https://app.zikanalytics.com/login', wait_until='load')

            # Fill login form
            page.fill('input#email', 's.h.01@hotmail.de')
            page.fill('input#password', '!gREwEKC5M#u!')

            # Submit form
            page.click('button[type="submit"]')

            # Wait for navigation
            page.wait_for_load_state('networkidle')
            # Wait for page to load
            page.wait_for_load_state('load')

            page.on('response', handle_response )
            input("Press Enter to continue...")
            browser.close()

    except Exception as e:
        print(f"An error occurred: {e}", file=sys.stderr)
        sys.exit(1)

if __name__ == "__main__":
    main()
</pre></body></html>