from lib2to3.pgen2.driver import Driver
from select import select
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.alert import Alert
from selenium.webdriver.support.ui import Select
import pandas as pd
import time
driver = webdriver.Chrome('chromedriver.exe')
driver.get('https://mallbo.epost.go.kr')
time.sleep(5)
e = driver.find_element_by_xpath('//*[@id="id"]')
e.send_keys('jwhan311')
e = driver.find_element_by_xpath('//*[@id="pw"]')
e.send_keys('posa02144!')
e = driver.find_element_by_id('login_btn')
e.click()
time.sleep(1)
try:
da = Alert(driver)
da.accept()
except:
print('알람창없음')
time.sleep(1)
driver.find_element_by_xpath('//*[@id="M113"]/a').click()
time.sleep(1)
driver.find_element_by_xpath('//*[@id="M1591"]/a').click()
time.sleep(1)
df1 = pd.read_csv('./temp.csv',encoding='cp949')
print(df1)
time.sleep(1)
for i in range(len(df1)):
time.sleep(1)
e=driver.find_element_by_xpath('//*[@id="search_text"]')
e.clear()
e.send_keys(df1.iat[i,1])
time.sleep(1)
driver.find_element_by_xpath('//*[@id="search_btn"]').click()
time.sleep(1)
driver.find_element_by_xpath('//*[@id="1"]').click()
time.sleep(1)
time.sleep(1)
try:
da = Alert(driver)
da.accept()
except:
print('알람창없음')
time.sleep(1)
time.sleep(1)
driver.execute_script("window.scrollTo(0,document.body.scrollHeight/2);")
driver.find_element_by_xpath('//*[@id="std_sell_prc"]').clear()
driver.find_element_by_xpath('//*[@id="std_sell_prc"]').send_keys(df1.iat[i,2])
driver.find_element_by_xpath('//*[@id="dc_apply_prc"]').clear()
driver.find_element_by_xpath('//*[@id="dc_apply_prc"]').send_keys(df1.iat[i,3])
firstStr=df1.iat[i,0][0:9]
print(firstStr)
lastStr=str(int(df1.iat[i,0][-1])-1)
print(firstStr+lastStr)
e = driver.find_element_by_xpath('//*[@id="dc_apply_strt_ymd"]')
e.clear()
e.send_keys(firstStr+lastStr)
if driver.find_element_by_xpath('//*[@id="goods_cellinfo_form"]/tbody/tr[5]/td/input[5]').get_attribute('checked'):
driver.find_element_by_xpath('//*[@id="goods_cellinfo_form"]/tbody/tr[5]/td/input[5]').click()
e = driver.find_element_by_xpath('//*[@id="dc_apply_end_ymd"]')
e.clear()
e.send_keys(df1.iat[i,0])
lastStr=str(int(df1.iat[i,0][-1])-4)
e = driver.find_element_by_xpath('//*[@id="supp_bgin_ymd"]')
e.clear()
e.send_keys(firstStr+lastStr)
firstStr=df1.iat[i,0][0:3]
firstStr2=str(int(df1.iat[i,0][3])+1)
middleStr=df1.iat[i,0][4:9]
lastStr=str(int(df1.iat[i,0][-1])-5)
e = driver.find_element_by_xpath('//*[@id="supp_end_ymd"]')
e.clear()
e.send_keys(firstStr+firstStr2+middleStr+lastStr)
print(firstStr)
try:
driver.execute_script("window.scrollTo(0,document.body.scrollHeight*3/5);")
if driver.find_element_by_xpath('//*[@id="goods_optn_apply_yn_Y"]').get_attribute('checked'):
print('옵션사용중임')
e = driver.find_elements_by_xpath('//*[@id="optn_table"]/tbody/tr')
e = len(e)-4
s = driver.find_elements_by_class_name('sNum')
for j in range(e):
s[-1-j].clear()
s[-1-j].send_keys(int(1000/e))
if driver.find_element_by_xpath('//*[@id="goods_optn_apply_yn_N"]').get_attribute('checked'):
print('옵션사용안하는중임')
except:
print('특산물상품임')
select=Select(driver.find_element_by_xpath('//*[@id="goods_stus_cd"]'))
select.select_by_value('01')
driver.find_element_by_xpath('//*[@id="stock_mgt_use_yn_Y"]').click()
firstStr=df1.iat[i,0][0:9]
print(firstStr)
lastStr=str(int(df1.iat[i,0][-1])-1)
print(firstStr+lastStr)
e = driver.find_element_by_xpath('//*[@id="stock_mgt_strt_ymd"]')
e.clear()
e.send_keys(firstStr+lastStr)
e = driver.find_element_by_xpath('//*[@id="stock_mgt_end_ymd"]')
e.clear()
e.send_keys(df1.iat[i,0])
currentStock=driver.find_element_by_xpath('//*[@id="stock_volm"]')
addStock=driver.find_element_by_xpath('//*[@id="add_stock_volm"]')
if driver.find_element_by_xpath('//*[@id="goods_optn_apply_yn_Y"]').get_attribute('checked'):
a = int(driver.find_element_by_xpath('//*[@id="stock_volm_before"]').get_attribute('value'))
driver.execute_script("""document.getElementById('add_stock_volm').value = """+str(-a))
print('옵션사용중이어서 추가재고량 맞춰서 세팅'+str(-a))
else:
if int(currentStock.get_attribute('value').strip().replace(',',''))>=1000:
addStock.clear()
addStock.send_keys(str(1000-int(currentStock.get_attribute('value').strip().replace(',',''))))
print(currentStock.get_attribute('value'))
print(addStock.get_attribute('value'))
else:
addStock.clear()
addStock.send_keys(str(1000+int(currentStock.get_attribute('value').strip().replace(',',''))))
print(currentStock.get_attribute('value'))
print(addStock.get_attribute('value'))
driver.execute_script("window.scrollTo(0,document.body.scrollHeight);")
select=Select(driver.find_element_by_xpath('//*[@id="goods_chg_reasn_cd"]'))
select.select_by_value('99')
driver.find_element_by_xpath('//*[@id="goods_chg_reasn_cont"]').send_keys('쇼핑25시 세팅')
driver.find_element_by_xpath('//*[@id="update_btn"]').click()
time.sleep(1)
try:
da = Alert(driver)
da.accept()
except:
print('알람창없음')
time.sleep(1)
try:
da = Alert(driver)
da.accept()
except:
print('알람창없음')
time.sleep(1)
driver.find_element_by_xpath('//*[@id="M712"]/a').click()
time.sleep(1)
driver.find_element_by_xpath('//*[@id="search_text"]').clear()
driver.find_element_by_xpath('//*[@id="search_text"]').send_keys(df1.iat[i,1])
time.sleep(1)
driver.find_element_by_xpath('//*[@id="search_btn"]').click()
time.sleep(1)
driver.find_element_by_xpath('//*[@id="jqg_gridList_1"]').click()
time.sleep(1)
select = Select(driver.find_element_by_xpath('//*[@id="appr_cd"]'))
select.select_by_value('03')
time.sleep(1)
driver.find_element_by_xpath('//*[@id="appr_btn"]').click()
time.sleep(1)
time.sleep(1)
try:
da = Alert(driver)
da.accept()
except:
print('알람창없음')
time.sleep(1)
try:
da = Alert(driver)
da.accept()
except:
print('알람창없음')
time.sleep(1)
driver.find_element_by_xpath('//*[@id="M1591"]/a').click()
time.sleep(1)