如果下一行为空,则暂停脚本

时间:2019-01-15 12:21:21

标签: python python-3.x for-loop while-loop selenium-chromedriver

我有这段代码可以循环运行:

while True:   #repeats script in infinity 


    df = pd.read_csv('screenshot.csv', header = 0, usecols= ['url','guid'])

    for index, row in df.iterrows():
        r = driver.get(row['url'])
        driver.execute_script("window.scrollTo(0, document.body.scrollHeight);") # takes a screen shot within a range of 2 seconds for each page and names it with the DT when the screenshot was taken 

        for n in range(2):
            file_name = str(row['guid'])
            driver.save_screenshot(file_name+ '.png') #saves screenshot with guid number
            it = iter(file_name) #iterated through file_name and skips duplicated ones
            for i in it:
                if i == file_name:       #avoids duplicated file names
                     continue
   df['url']    
   for i, row in df.iterrows() :        #if url row url is empty will sleep for 10 minutes
       if row['url'] == '':
           time.sleep(10)

           print('guid is' + str(file_name))



print(file_name)  #prints the name file name
driver.quit() 

我的问题与这部分有关:

df['url']    
   for i, row in df.iterrows() :        #if url row url is empty will sleep for 10 minutes
       if row['url'] == '':
           time.sleep(10)

如果列url中的下一行为空,我需要while循环来暂停。 当下一行为空时,脚本会不断重复运行,而不会应用休眠时间。你能帮我吗?

0 个答案:

没有答案