mirror of
https://github.com/henry4682/linebot_finance.git
synced 2026-05-16 04:41:52 +00:00
feat: line_invoice_fetcher
All checks were successful
Oracle-Deploy / redeploy (push) Successful in 31s
All checks were successful
Oracle-Deploy / redeploy (push) Successful in 31s
This commit is contained in:
54
app/getLineTokenManual.py
Normal file
54
app/getLineTokenManual.py
Normal file
@@ -0,0 +1,54 @@
|
||||
from playwright.sync_api import sync_playwright
|
||||
import time
|
||||
import os
|
||||
|
||||
# 設定狀態儲存路徑
|
||||
USER_DATA_DIR = os.path.join(os.getcwd(), "line_user_data_firefox")
|
||||
|
||||
def run():
|
||||
with sync_playwright() as p:
|
||||
print("🔧 正在啟動 Firefox...")
|
||||
# 1. 確保 headless=False
|
||||
context = p.firefox.launch_persistent_context(
|
||||
user_data_dir=USER_DATA_DIR,
|
||||
headless=False,
|
||||
slow_mo=500, # 讓動作慢一點,方便觀察
|
||||
user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:123.0) Gecko/20100101 Firefox/123.0"
|
||||
)
|
||||
|
||||
page = context.new_page()
|
||||
|
||||
# 攔截邏輯
|
||||
def intercept_request(request):
|
||||
if "graphql" in request.url:
|
||||
token = request.headers.get("x-parse-session-token")
|
||||
if token:
|
||||
print(f"\n🔥 🔥 抓到 Token 了!! 🔥 🔥")
|
||||
print(f"Token: {token}")
|
||||
with open(".env.token", "w") as f:
|
||||
f.write(f"LINE_INVOICE_TOKEN={token}")
|
||||
print(f"✅ 已存入 .env.token\n")
|
||||
|
||||
page.on("request", intercept_request)
|
||||
|
||||
try:
|
||||
print("🚀 前往 LINE 發票管家...")
|
||||
page.goto("https://invoice.line.me/", wait_until="domcontentloaded")
|
||||
|
||||
print("⏳ 視窗應該已經彈出!請在視窗內完成登入。")
|
||||
print("注意:登入後請留在發票列表頁面,直到終端機印出 Token。")
|
||||
|
||||
# 給妳 2 分鐘慢慢登入
|
||||
for i in range(120, 0, -1):
|
||||
if i % 10 == 0:
|
||||
print(f"倒數 {i} 秒...")
|
||||
time.sleep(1)
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ 發生錯誤: {e}")
|
||||
finally:
|
||||
context.close()
|
||||
print("👋 瀏覽器已關閉。")
|
||||
|
||||
if __name__ == "__main__":
|
||||
run()
|
||||
Reference in New Issue
Block a user