Python 循环x次通过函数
我有一个使用selenium的程序。在这个程序中,我有一个带有Python 循环x次通过函数,python,loops,if-statement,tkinter,listbox,Python,Loops,If Statement,Tkinter,Listbox,我有一个使用selenium的程序。在这个程序中,我有一个带有列表框的tkinter GUI 通过在输入字段中输入名称并使用按钮添加名称,可以用名称填充的列表框 在我填写完我的列表后,我想检查每个名字并执行一个搜索循环 这是到目前为止我的代码(在本例中尝试将其简化): 在本例中,我想查看列表中的每个项目,在URL上搜索名称,如果在特定xpath中找到并弹出名称,则单击该名称 在那之后,这就是我不能正确完成的,我想在循环中执行一个函数。 该函数应该循环5次,然后转到我列表框中的下一个na,e,并执
列表框的tkinter GUI
通过在输入字段中输入名称并使用按钮添加名称,可以用名称填充的列表框
在我填写完我的列表后,我想检查每个名字并执行一个搜索循环
这是到目前为止我的代码(在本例中尝试将其简化):
在本例中,我想查看列表中的每个项目,在URL上搜索名称,如果在特定xpath中找到并弹出名称,则单击该名称
在那之后,这就是我不能正确完成的,我想在循环中执行一个函数。
该函数应该循环5次,然后转到我列表框中的下一个na,e,并执行相同的操作(因此实际上,对于我列表框中的所有名称,它应该执行5次)
这是要执行的循环:
def example(int_user_input_max_price, int_choose_speed): # buy only routine
# start buy only mode
global start_process, exit_tool
exit_tool = False
start_process = True
if start_process is True:
time.sleep(1)
btn_search = driver.find_element_by_xpath('/html/body/main/section/section/div[2]/div/div[2]/div/div[2]/button[2]')
# set max price
ipt_max_price = driver.find_element_by_xpath(
ipt_max_price.click()
time.sleep(1)
ipt_max_price.send_keys(int_user_input_max_price)
time.sleep(1)
# Set min price
int_min_price = 150
# Set max players bought
int_max_players_bought = 100
int_players_bought = 0
# Buy until 100 players were bought
while int_players_bought < int_max_players_bought:
else:
def示例(int_user_input_max_price,int_choose_speed):#仅购买例程
#开始只买模式
全局启动\u进程,退出\u工具
退出工具=错误
启动进程=真
如果启动\u过程为真:
时间。睡眠(1)
btn_search=driver.find_element_by_xpath('/html/body/main/section/section/div[2]/div/div[2]/div/div[2]/button[2]'))
#设定最高价格
ipt_max_price=driver.find_element_by_xpath(
ipt_最高价格。单击()
时间。睡眠(1)
ipt_最高价格。发送密钥(int_用户_输入_最高价格)
时间。睡眠(1)
#设定最低价格
国际最低价格=150
#设置玩家购买的最大值
int_max_players_bunded=100
int\u玩家\u购买=0
#购买直到购买100名球员
当int_玩家购买
我不想重复我所有代码的含义,我只想知道,我如何才能使这个example()
执行5次,然后返回到列表框中的下一项
如果需要任何进一步的输入,请让我知道
编辑1:
我有一份足球运动员的名单,用我的代码,我正在自动开发一个国际足联比赛的网络应用程序
我的程序正在通过列表中的名字搜索球员,并试图在转会市场上购买它(example()
)
我想让它成为可能,用户可以向列表框中添加一些名称,并让程序循环遍历列表中的所有项目。它应该执行example()
x次,然后返回并对列表框中的下一个项目执行相同的操作
我在想,如果一个计数器能帮上忙,那么它在通过example()
的每个循环后都能输入+=1。
但是我无法将代码整合起来。也可以在摘要中包含您想要实现的目标?添加了一个摘要它应该做什么;-)下面的答案没有帮助?没有,因为它必须考虑许多方面。但我现在明白了。我在代码中做了大量的重写。泰尔
def example(int_user_input_max_price, int_choose_speed): # buy only routine
# start buy only mode
global start_process, exit_tool
exit_tool = False
start_process = True
if start_process is True:
time.sleep(1)
btn_search = driver.find_element_by_xpath('/html/body/main/section/section/div[2]/div/div[2]/div/div[2]/button[2]')
# set max price
ipt_max_price = driver.find_element_by_xpath(
ipt_max_price.click()
time.sleep(1)
ipt_max_price.send_keys(int_user_input_max_price)
time.sleep(1)
# Set min price
int_min_price = 150
# Set max players bought
int_max_players_bought = 100
int_players_bought = 0
# Buy until 100 players were bought
while int_players_bought < int_max_players_bought:
else: