Python3 goto assignment 作为无限 while 循环?
Python3 goto assignment as infinite while-loop?
我是python新手,不明白如何在python3/selenium中分配“goto”标签。我知道有 none,但是我怎样才能编写我的脚本,以便它不会在执行无限 while 循环时失败(这里用伪代码编写)?:
while True:
for-loop1
something happens
for-loop2
something else is happening
for-loop3
even more stuff happens
try:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "li:not(.disabled)>a[data-page='next']"))).click() # checks for other page
print("There is another page.")
time.sleep( 2 ) # wait to load
except NoSuchElementException:
print("No further page exists. Bye, bye!")
break
driver.quit()
我收到以下错误消息:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "li:not(.disabled)>a[data-page='next']"))).click() # checks for other page
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/support/wait.py", line 80, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
编辑:
问题已解决:
driver.find_element_by_css_selector("li:not(.disabled)>a[data-page='next']").click()
如果我正确理解你的问题,你根本不需要使用 "goto"。您可以通过使用围绕您的 for 循环的简单 while 循环来解决它。
while True:
for things in loop1:
do stuff
for things in loop2:
do more stuff
if there_are_no_more_pages:
break
我是python新手,不明白如何在python3/selenium中分配“goto”标签。我知道有 none,但是我怎样才能编写我的脚本,以便它不会在执行无限 while 循环时失败(这里用伪代码编写)?:
while True:
for-loop1
something happens
for-loop2
something else is happening
for-loop3
even more stuff happens
try:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "li:not(.disabled)>a[data-page='next']"))).click() # checks for other page
print("There is another page.")
time.sleep( 2 ) # wait to load
except NoSuchElementException:
print("No further page exists. Bye, bye!")
break
driver.quit()
我收到以下错误消息:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "li:not(.disabled)>a[data-page='next']"))).click() # checks for other page
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/support/wait.py", line 80, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
编辑:
问题已解决:
driver.find_element_by_css_selector("li:not(.disabled)>a[data-page='next']").click()
如果我正确理解你的问题,你根本不需要使用 "goto"。您可以通过使用围绕您的 for 循环的简单 while 循环来解决它。
while True:
for things in loop1:
do stuff
for things in loop2:
do more stuff
if there_are_no_more_pages:
break