feat(order): 지오영/수인 선택적 주문 + 장바구니 보존 기능
- internal_code DB 저장 → 프론트에서 선택한 제품 그대로 주문 - 기존 장바구니 백업/복구로 사용자 장바구니 보존 - 수인약품 submit_order() 수정 (체크박스 제외 방식) - 테스트 파일 정리 및 문서 추가
This commit is contained in:
79
backend/capture_order2.py
Normal file
79
backend/capture_order2.py
Normal file
@@ -0,0 +1,79 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
네트워크 캡처 v2 - 새로고침 후에도 캡처
|
||||
"""
|
||||
import sys; sys.path.insert(0, '.'); import wholesale_path
|
||||
from wholesale import SooinSession
|
||||
from playwright.sync_api import sync_playwright
|
||||
import time
|
||||
|
||||
s = SooinSession()
|
||||
print('로그인...')
|
||||
s.login()
|
||||
|
||||
# 먼저 장바구니 비우기
|
||||
s.clear_cart()
|
||||
|
||||
# 코자정 담기
|
||||
print('코자정 검색...')
|
||||
result = s.search_products('코자정')
|
||||
product = result['items'][0] if result.get('items') else None
|
||||
|
||||
if product:
|
||||
print(f"제품: {product['name']} - {product['price']:,}원")
|
||||
s.add_to_cart(product['internal_code'], qty=1,
|
||||
price=product['price'], stock=product['stock'])
|
||||
print('장바구니에 담음!')
|
||||
|
||||
cart = s.get_cart()
|
||||
print(f"장바구니: {cart['total_items']}개")
|
||||
|
||||
print('\n브라우저 열기...')
|
||||
|
||||
with sync_playwright() as p:
|
||||
browser = p.chromium.launch(headless=False)
|
||||
context = browser.new_context()
|
||||
|
||||
# 쿠키 복사
|
||||
for c in s.session.cookies:
|
||||
context.add_cookies([{
|
||||
'name': c.name,
|
||||
'value': c.value,
|
||||
'domain': c.domain or 'sooinpharm.co.kr',
|
||||
'path': c.path or '/'
|
||||
}])
|
||||
|
||||
page = context.new_page()
|
||||
|
||||
# 모든 요청 캡처 (지속적)
|
||||
captured = []
|
||||
def capture(request):
|
||||
if 'BagOrder' in request.url and request.method == 'POST':
|
||||
data = request.post_data or ''
|
||||
captured.append(data)
|
||||
print('\n' + '='*60)
|
||||
print('🎯 POST 캡처!')
|
||||
print('='*60)
|
||||
for param in data.split('&')[:30]: # 주요 파라미터만
|
||||
if '=' in param:
|
||||
k, v = param.split('=', 1)
|
||||
if v: # 값이 있는 것만
|
||||
print(f' {k}: {v[:60]}')
|
||||
print('='*60)
|
||||
|
||||
context.on('request', capture) # context 레벨에서 캡처
|
||||
|
||||
page.goto('http://sooinpharm.co.kr/Service/Order/Order.asp')
|
||||
|
||||
print('\n✅ 준비 완료!')
|
||||
print('👆 F5로 새로고침 후 주문전송 버튼 클릭!')
|
||||
print('\n(Enter 누르면 종료)')
|
||||
input()
|
||||
|
||||
# 캡처된 데이터 파일로 저장
|
||||
if captured:
|
||||
with open('captured_post.txt', 'w', encoding='utf-8') as f:
|
||||
f.write(captured[0])
|
||||
print('\n📁 captured_post.txt 저장됨')
|
||||
|
||||
browser.close()
|
||||
Reference in New Issue
Block a user