[英]How can I modify this code so it doesn't go back to the beginning of the function, but a little bit after the beginning?
[英]How to stop all code and go back to the beginning
我正在使用 selenium 注册游戏帐号。 而我用的是租号服务的api,但是因为用户太多,有些号码就用不到了。 我使用了 if 和 elif 方法,这样当我收到代码时,它将填充 web。
我尝试使用 start_time = time.time() 来计算状态是否超过 90 秒仍然返回 0 然后停止整个代码并从 for 循环再次运行,但是'返回'仅停止'input_phone_number'function,而不是所有功能。 这是我使用的代码:
def input_phone_number():
while True:
try:
status_code = requests.get(f'https://api.viotp.com/session/getv2?requestId={request_id}&token={token}')
code_data = status_code.json()['data']
status = code_data['Status']
code = code_data['Code']
if status == 0:
sleep(5)
elif status == 1:
# Locate the element with the CSS selector '#code' and send the code as keyboard input
driver.find_element(By.CSS_SELECTOR, '#code').send_keys(code)
break
if time.time() - start_time > 90:
driver.close()
return
这是原始代码:
for index, row in df.iterrows():
Firstname = row['Fname']
Lastname = row['Lname']
Username = row['Username']
Password = row['Password']
def open_url():
#code
def input_information():
#code
def input_phone_number():
response = requests.get(f'https://api.viotp.com/request/getv2?token={token}&serviceId=3')
data = response.json()['data']
number = data['phone_number']
balance = data['balance']
print('Phone Number:', number, '|', 'Balance:', balance)
sleep(3)
WebDriverWait(driver, 20).until(
EC.presence_of_element_located((By.CSS_SELECTOR, '#phoneNumberId'))
)
driver.find_element(By.CSS_SELECTOR, '#phoneNumberId').send_keys(number)
sleep(3)
driver.find_element(By.CSS_SELECTOR, '#view_container > div > div > div.pwWryf.bxPAYd > div > div.zQJV3 > div > div.qhFLie > div > div > button > span').click()
request_id = data['request_id']
status = 0
while status != 1:
status_code = requests.get(f'https://api.viotp.com/session/getv2?requestId={request_id}&token={token}')
code_data = status_code.json()['data']
code = code_data['Code']
status = code_data['Status']
if status == 0:
sleep(5) # Sleep for 5 seconds before repeating the request
elif status == 1:
# Locate the element with the CSS selector '#code' and send the code as keyboard input
driver.find_element(By.CSS_SELECTOR, '#code').send_keys(code)
sleep(3)
driver.find_element(By.CSS_SELECTOR, '#view_container > div > div > div.pwWryf.bxPAYd > div > div.zQJV3 > div > div.qhFLie > div > div > button > span').click()
def input_birthdate():
#code
open_url()
input_information()
input_phone_number()
input_birthdate()
有人能帮我吗? 非常感谢!
我要做的是不返回任何内容,而是返回一个字符串“continue”,在调用 input_phone_number() 之后我会检查返回值是否为“continue”,如果是,我会使用 continue to go 到for循环的下一次迭代。
def input_phone_number():
while True:
try:
status_code = requests.get(f'https://api.viotp.com/session/getv2?requestId={request_id}&token={token}')
code_data = status_code.json()['data']
status = code_data['Status']
code = code_data['Code']
if status == 0:
sleep(5)
elif status == 1:
# Locate the element with the CSS selector '#code' and send the code as keyboard input
driver.find_element(By.CSS_SELECTOR, '#code').send_keys(code)
break
if time.time() - start_time > 90:
driver.close()
return "continue"
open_url()
input_information()
result = input_phone_number()
if result == "continue":
continue
input_birthdate()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.