add: login delay
This commit is contained in:
55
销售订单自动导入.py
55
销售订单自动导入.py
@@ -236,14 +236,6 @@ def main():
|
||||
if args.automation == 'none': return 0
|
||||
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:
|
||||
driver = webdriver.Chrome()
|
||||
driver.set_page_load_timeout(args.timeout)
|
||||
@@ -288,14 +280,23 @@ def main():
|
||||
# 其他错误
|
||||
raise e
|
||||
|
||||
try:
|
||||
locate("input.account").send_keys(args.xm_username)
|
||||
locate("input#password").send_keys(args.xm_password)
|
||||
locate("input.agree-checkbox").click()
|
||||
locate("button.login-btn").click()
|
||||
except Exception as e:
|
||||
print(f'[!!!!] 登录网页时发生了错误:{e}')
|
||||
return 81
|
||||
if bool(args.xm_username) and bool(args.xm_password):
|
||||
try:
|
||||
locate("input.account").send_keys(args.xm_username)
|
||||
locate("input#password").send_keys(args.xm_password)
|
||||
locate("input.agree-checkbox").click()
|
||||
locate("button.login-btn").click()
|
||||
except Exception as e:
|
||||
print(f'[!!!!] 登录网页时发生了错误:{e}')
|
||||
return 81
|
||||
else:
|
||||
print("[警告] 未提供有效登录凭证")
|
||||
key = input('[????] 请确认登录状态:已登录 (Y) / 取消操作 (N): ')
|
||||
if key in ['Y', 'y']:
|
||||
print('[信息] 已确认操作')
|
||||
else:
|
||||
print('[信息] 已取消操作')
|
||||
return 0
|
||||
|
||||
try:
|
||||
locate(".layout-sidebar ul li:nth-child(10) div div").click()
|
||||
@@ -343,7 +344,17 @@ def main():
|
||||
|
||||
# 设置每页显示记录数
|
||||
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 = []
|
||||
|
||||
while True:
|
||||
@@ -400,20 +411,16 @@ def main():
|
||||
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")
|
||||
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':
|
||||
# 定位元素
|
||||
driver.execute_script("arguments[0].scrollTo(0, arguments[0].scrollHeight);", wrapper)
|
||||
locate(".cell[data-cci='4'] input", parent=items[-1], condition=None)
|
||||
locate(".cell[data-cci='5'] input", parent=items[-1], 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)
|
||||
source = locate(".cell[data-cci='4'] input", parent=items[idx], condition=None)
|
||||
target = locate(".cell[data-cci='6'] input", parent=items[idx], condition=None)
|
||||
# 填入含税成本价
|
||||
price = source.get_attribute('value')
|
||||
target.send_keys(price)
|
||||
break
|
||||
except Exception as e:
|
||||
print(f"[警告] {number}: 编辑运费时发生错误:{e}")
|
||||
warn = True
|
||||
|
||||
Reference in New Issue
Block a user