Add HTTP server with CORS support, cookie management, and real-time cookie viewer

This commit is contained in:
2025-02-16 23:32:36 +01:00
parent 28f9d2eedf
commit e2f6f2e82c
4 changed files with 2749 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
import json
import time
import pandas as pd
from playwright.sync_api import sync_playwright
# Archivo donde se guardarán las cookies
COOKIES_FILE = "cookies.json"
def save_cookies(context):
"""Guarda las cookies actuales en un archivo JSON."""
cookies = context.cookies()
df = pd.DataFrame(cookies)
# Convertir a JSON
with open(COOKIES_FILE, "w", encoding="utf-8") as f:
json.dump(cookies, f, indent=4, ensure_ascii=False)
print(f"Cookies guardadas en {COOKIES_FILE}")
with sync_playwright() as p:
browser = p.chromium.launch(headless=False)
context = browser.new_context()
page = context.new_page()
page.goto("https://xataka.com")
print("Navegador abierto. Puedes usarlo libremente.")
try:
while True:
save_cookies(context)
time.sleep(10) # Espera 10 segundos antes de actualizar las cookies
except KeyboardInterrupt:
print("\nCerrando navegador...")
browser.close()