- internal_code DB 저장 → 프론트에서 선택한 제품 그대로 주문 - 기존 장바구니 백업/복구로 사용자 장바구니 보존 - 수인약품 submit_order() 수정 (체크박스 제외 방식) - 테스트 파일 정리 및 문서 추가
83 lines
2.4 KiB
Python
83 lines
2.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
네트워크 캡처용 - 약사님이 직접 주문 버튼 클릭
|
|
"""
|
|
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()
|
|
|
|
# 장바구니에 코자정 담기
|
|
print('\n코자정 검색...')
|
|
result = s.search_products('코자정 50mg PTP')
|
|
product = None
|
|
for item in result.get('items', []):
|
|
if 'PTP' in item['name']:
|
|
product = item
|
|
break
|
|
|
|
if product:
|
|
print(f"제품: {product['name']} - {product['price']:,}원")
|
|
s.add_to_cart(product['internal_code'], qty=1,
|
|
price=product['price'], stock=product['stock'])
|
|
print('장바구니에 담음!')
|
|
else:
|
|
print('제품 못 찾음')
|
|
|
|
# 장바구니 확인
|
|
cart = s.get_cart()
|
|
print(f"\n장바구니: {cart['total_items']}개, {cart['total_amount']:,}원")
|
|
|
|
print('\n' + '='*50)
|
|
print('브라우저 열기 + 네트워크 캡처 시작')
|
|
print('='*50)
|
|
|
|
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()
|
|
|
|
# 네트워크 요청 캡처
|
|
def on_request(request):
|
|
if 'BagOrder' in request.url and request.method == 'POST':
|
|
print('\n' + '='*50)
|
|
print('🎯 POST 요청 캡처!')
|
|
print('='*50)
|
|
print(f'URL: {request.url}')
|
|
print(f'\nPOST 데이터:')
|
|
data = request.post_data or ''
|
|
# 파라미터별로 출력
|
|
for param in data.split('&'):
|
|
if '=' in param:
|
|
key, val = param.split('=', 1)
|
|
print(f' {key}: {val[:50]}')
|
|
print('='*50)
|
|
|
|
page.on('request', on_request)
|
|
|
|
# 주문 페이지로 이동
|
|
page.goto('http://sooinpharm.co.kr/Service/Order/Order.asp')
|
|
|
|
print('\n✅ 브라우저 준비 완료!')
|
|
print('👆 주문전송 버튼을 클릭해주세요!')
|
|
print('\n(Enter 누르면 브라우저 닫힘)')
|
|
input()
|
|
|
|
browser.close()
|
|
|
|
print('\n완료!')
|