这是我想要做的:
以下代码对我不起作用:
loop_1 = 0
while loop_1 < 3:
##### download the file
driver.find_element_by_link_text('Download Search Results').click()
##### check the existence of the downloaded file;
##### if not there within 5 seconds, download the file again
loop_2 = 0
while loop_2 < 100:
f_exists = os.path.isfile('/Users/jeff/downloaded.csv')
if f_exists != True:
print(loop_2, 'file DOES NOT exist')
loop_2 = loop_2 + 1
time.sleep(.05)
if f_exists == True:
print(loop_1, 'file exists')
break
loop_1 = loop_1 + 1
答案 0 :(得分:0)
为什么你看起来更干净时使用while循环?
for i in range(0,3):
driver.find_element_by_link_text('Download Search Results').click()
for j in range(0,101):
f_exists = os.path.isfile('/Users/jeff/downloaded.csv')
if not f_exists:
print(j, 'file DOES NOT exist')
time.sleep(.05)
else:
print(i, 'file exists')
return