This commit is contained in:
Prox_Win10-B 2024-11-01 15:57:06 +09:00
commit f9098c2b34
4 changed files with 51543 additions and 29 deletions

File diff suppressed because one or more lines are too long

View File

@ -39,7 +39,12 @@ option_box_selector = '//*[@id="productMainContentContainerId"]/div[1]/div[2]/di
excluded_option_marker = '.bXsMpn.sc-dfauwV'
; delete_button_selector = 'div#productMainContentContainerId div.lesrZh.sc-bYHUQc:nth-child({index}) span:has-text("삭제")'
; delete_button_selector = 'div#productMainContentContainerId div.lesrZh.sc-bYHUQc:nth-child({index}) div.sc-igZIGL.kQDmyq'
delete_button_selector = '.kQDmyq.sc-igZIGL'
; delete_button_selector = '.kQDmyq.sc-igZIGL'
delete_button_selector_template = '//*[@id="productMainContentContainerId"]/div[1]/div[2]/div/div/div[2]/div/div[1]/div/div/div[2]/div/div/div[5]/div[1]/div/div/ul/li[{index}]/div/div[1]/div/div[2]/div/div[2]/div[1]/div/span'
fallback1_delete_button_selector_template = 'div#productMainContentContainerId li:nth-child({index}) > div > div:nth-child(1) > div > div:nth-child(2) > div > div.ant-row.ant-row-no-wrap.ant-row-space-between.ant-row-middle.css-1li46mu > div:nth-child(1) > div > span'
confirm_delete_button_selector = '.ant-modal.css-1li46mu.ant-modal-confirm.ant-modal-confirm-confirm button:has-text("삭제")'
add_button_selector2 = 'div#productMainContentContainerId div.lesrZh.sc-bYHUQc:nth-child({index}) > .sc-dRGYJT.hmQUGb'
add_button_selector = '//*[@id="productMainContentContainerId"]/div[1]/div[2]/div/div/div[2]/div/div[1]/div/div/div[2]/div/div/div[5]/div[1]/div/div/ul/li[{index}]/div/div[1]/div/div[2]/div/div/img'
@ -174,24 +179,3 @@ option_input_field_locator = 'div#productMainContentContainerId > div > div > di
# Save
save_button_locator = 'button:has-text("저장하기")'
[CategoryMargins]
categories = 가구, 농기구
[가구]
threshold_1 = 100000 # 10만원
extra_margin_1 = 10000 # 2만원 초과마다 1만원 추가
unit_1 = 20000
threshold_2 = 200000 # 20만원
extra_margin_2 = 15000 # 2만원 초과마다 1.5만원 추가
unit_2 = 20000
[농기구]
threshold_1 = 100000 # 10만원
extra_margin_1 = 5000 # 2만원 초과마다 0.5만원 추가
unit_1 = 20000
threshold_2 = 200000 # 20만원
extra_margin_2 = 10000 # 2만원 초과마다 1만원 추가
unit_2 = 20000

View File

@ -90,7 +90,8 @@ class LocatorManager:
'price_selector_template': self.config.get('OptionLocators', 'price_selector_template').strip("'"),
'option_box_selector': self.config.get('OptionLocators', 'option_box_selector').strip("'"),
'excluded_option_marker': self.config.get('OptionLocators', 'excluded_option_marker').strip("'"),
'delete_button_selector': self.config.get('OptionLocators', 'delete_button_selector').strip("'"),
'delete_button_selector_template': self.config.get('OptionLocators', 'delete_button_selector_template').strip("'"),
'fallback1_delete_button_selector_template': self.config.get('OptionLocators', 'fallback1_delete_button_selector_template').strip("'"),
'confirm_delete_button_selector': self.config.get('OptionLocators', 'confirm_delete_button_selector').strip("'"),
'add_button_selector': self.config.get('OptionLocators', 'add_button_selector').strip("'"),
'file_upload_button_selector': self.config.get('OptionLocators', 'file_upload_button_selector').strip("'"),

View File

@ -34,7 +34,8 @@ class OptionHandler:
self.option_box_selector = self.locator_manager.get_locator('OptionLocators', 'option_box_selector')
self.excluded_option_marker = self.locator_manager.get_locator('OptionLocators', 'excluded_option_marker')
self.delete_button_selector = self.locator_manager.get_locator('OptionLocators', 'delete_button_selector')
self.delete_button_selector_template = self.locator_manager.get_locator('OptionLocators', 'delete_button_selector_template')
self.fallback1_delete_button_selector_template = self.locator_manager.get_locator('OptionLocators', 'fallback1_delete_button_selector_template')
self.confirm_delete_button_selector = self.locator_manager.get_locator('OptionLocators', 'confirm_delete_button_selector')
self.add_button_selector = self.locator_manager.get_locator('OptionLocators', 'add_button_selector')
self.file_upload_button_selector = self.locator_manager.get_locator('OptionLocators', 'file_upload_button_selector')
@ -206,7 +207,7 @@ class OptionHandler:
return self.option_info
# 3. 가격 낮은 순 정렬 클릭
# await self.low_order_click()
await self.low_order_click()
try:
self.logger.info(f"옵션 정보 수집")
@ -760,13 +761,30 @@ class OptionHandler:
if is_success_translated and os.path.exists(translated_image_path):
# 삭제 버튼 클릭
# delete_button = await self.page.query_selector(delete_button_selector)
delete_button = await option_box.query_selector(".sc-igZIGL.kQDmyq")
self.logger.debug(f"{index}번째 옵션의 이미지 삭제 버튼 가져오기")
try:
# 기본 선택자로 삭제 버튼 찾기
# delete_button = option_box.query_selector(self.delete_button_selector)
delete_button = self.page.locator(f'{self.delete_button_selector_template.format(index=index)}')
await delete_button.wait_for(state="attached", timeout=5000) # 타임아웃 설정
if not await delete_button.is_visible():
# fallback으로 재시도
delete_button = self.page.locator(f'xpath={self.fallback1_delete_button_selector.format(index=index)}')
delete_button.set_timeout(5000)
if await delete_button.is_visible():
await delete_button.click()
self.logger.debug(f"{index}번째 옵션의 삭제 버튼 클릭")
except Exception as e:
self.logger.error(f"{index}번째 옵션의 삭제 버튼을 찾는 중 오류 발생: {e}", exc_info=True)
if delete_button:
await delete_button.click()
self.logger.debug(f"{index}번째 옵션의 이미지 삭제 버튼 클릭")
# await delete_button.click()
# self.logger.debug(f"{index}번째 옵션의 이미지 삭제 버튼 클릭")
confirm_delete_button = await self.page.wait_for_selector(self.confirm_delete_button_selector)
self.logger.debug(f"{index}번째 옵션의 이미지 삭제확인 버튼 가져오기")
if confirm_delete_button:
@ -795,6 +813,8 @@ class OptionHandler:
self.logger.debug(f"{index}번째 옵션에 이미지가 업로드되었습니다.")
else:
self.logger.error(f"{index}번째 옵션의 파일 입력 요소를 찾을 수 없습니다.")
except Exception as e:
self.logger.error(f"{index}번째 옵션 이미지 번역 중 오류 발생: {e}", exc_info=True)
finally:
# 파일 사용 후 0.5초 대기하여 접근 완료 보장