add: login delay
This commit is contained in:
55
销售订单自动导入.py
55
销售订单自动导入.py
@@ -236,14 +236,6 @@ def main():
|
|||||||
if args.automation == 'none': return 0
|
if args.automation == 'none': return 0
|
||||||
print('[信息] 正在启动自动化程序')
|
print('[信息] 正在启动自动化程序')
|
||||||
|
|
||||||
if not bool(args.xm_username):
|
|
||||||
print(f"[!!!!] 错误:缺少参数 'xm-username'(小满账号邮箱)")
|
|
||||||
return 4
|
|
||||||
|
|
||||||
if not bool(args.xm_password):
|
|
||||||
print(f"[!!!!] 错误:缺少参数 'xm-password'(小满账号密码)")
|
|
||||||
return 5
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
driver = webdriver.Chrome()
|
driver = webdriver.Chrome()
|
||||||
driver.set_page_load_timeout(args.timeout)
|
driver.set_page_load_timeout(args.timeout)
|
||||||
@@ -288,14 +280,23 @@ def main():
|
|||||||
# 其他错误
|
# 其他错误
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
try:
|
if bool(args.xm_username) and bool(args.xm_password):
|
||||||
locate("input.account").send_keys(args.xm_username)
|
try:
|
||||||
locate("input#password").send_keys(args.xm_password)
|
locate("input.account").send_keys(args.xm_username)
|
||||||
locate("input.agree-checkbox").click()
|
locate("input#password").send_keys(args.xm_password)
|
||||||
locate("button.login-btn").click()
|
locate("input.agree-checkbox").click()
|
||||||
except Exception as e:
|
locate("button.login-btn").click()
|
||||||
print(f'[!!!!] 登录网页时发生了错误:{e}')
|
except Exception as e:
|
||||||
return 81
|
print(f'[!!!!] 登录网页时发生了错误:{e}')
|
||||||
|
return 81
|
||||||
|
else:
|
||||||
|
print("[警告] 未提供有效登录凭证")
|
||||||
|
key = input('[????] 请确认登录状态:已登录 (Y) / 取消操作 (N): ')
|
||||||
|
if key in ['Y', 'y']:
|
||||||
|
print('[信息] 已确认操作')
|
||||||
|
else:
|
||||||
|
print('[信息] 已取消操作')
|
||||||
|
return 0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
locate(".layout-sidebar ul li:nth-child(10) div div").click()
|
locate(".layout-sidebar ul li:nth-child(10) div div").click()
|
||||||
@@ -343,7 +344,17 @@ def main():
|
|||||||
|
|
||||||
# 设置每页显示记录数
|
# 设置每页显示记录数
|
||||||
time.sleep(args.interval) #6
|
time.sleep(args.interval) #6
|
||||||
driver.get(driver.current_url.replace('page_size%22%3A20%2C%22', f'page_size%22%3A{args.per_page}%2C%22'))
|
url = driver.current_url
|
||||||
|
param = f'%22page_size%22%3A{args.per_page}%7D'
|
||||||
|
|
||||||
|
print('url before: ' + url)
|
||||||
|
|
||||||
|
if 'page_size' in url: url = url.replace('%22page_size%22%3A20%7D', param)
|
||||||
|
else: url += param
|
||||||
|
|
||||||
|
print('url after: ' + url)
|
||||||
|
|
||||||
|
driver.get(url)
|
||||||
modified = []
|
modified = []
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
@@ -400,20 +411,16 @@ def main():
|
|||||||
driver.execute_script("arguments[0].scrollTo(0, arguments[0].scrollHeight);", wrapper)
|
driver.execute_script("arguments[0].scrollTo(0, arguments[0].scrollHeight);", wrapper)
|
||||||
items = wrapper.find_elements(By.CSS_SELECTOR, "div.vue-recycle-scroller__item-wrapper div.vue-recycle-scroller__item-view")
|
items = wrapper.find_elements(By.CSS_SELECTOR, "div.vue-recycle-scroller__item-wrapper div.vue-recycle-scroller__item-view")
|
||||||
driver.execute_script("arguments[0].scrollIntoView({ block: 'start', inline: 'end' });", items[idx])
|
driver.execute_script("arguments[0].scrollIntoView({ block: 'start', inline: 'end' });", items[idx])
|
||||||
product = locate(f".product-info-group-product-name input", parent=items[-1], condition=None)
|
product = locate(f".product-info-group-product-name input", parent=items[idx], condition=None)
|
||||||
|
|
||||||
if product.get_attribute('value') == 'port':
|
if product.get_attribute('value') == 'port':
|
||||||
# 定位元素
|
# 定位元素
|
||||||
driver.execute_script("arguments[0].scrollTo(0, arguments[0].scrollHeight);", wrapper)
|
driver.execute_script("arguments[0].scrollTo(0, arguments[0].scrollHeight);", wrapper)
|
||||||
locate(".cell[data-cci='4'] input", parent=items[-1], condition=None)
|
source = locate(".cell[data-cci='4'] input", parent=items[idx], condition=None)
|
||||||
locate(".cell[data-cci='5'] input", parent=items[-1], condition=None)
|
target = locate(".cell[data-cci='6'] input", parent=items[idx], condition=None)
|
||||||
|
|
||||||
target = locate(".cell[data-cci='6'] input", parent=items[-1], condition=None)
|
|
||||||
source = locate(".cell[data-cci='7'] input", parent=items[-1], condition=None)
|
|
||||||
# 填入含税成本价
|
# 填入含税成本价
|
||||||
price = source.get_attribute('value')
|
price = source.get_attribute('value')
|
||||||
target.send_keys(price)
|
target.send_keys(price)
|
||||||
break
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"[警告] {number}: 编辑运费时发生错误:{e}")
|
print(f"[警告] {number}: 编辑运费时发生错误:{e}")
|
||||||
warn = True
|
warn = True
|
||||||
|
|||||||
Reference in New Issue
Block a user