import gspread
from oauth2client.service_account import ServiceAccountCredentials as sac
scope = ['https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive']
creds = sac.from_json_keyfile_name('client_secrets.json', scope)
client = gspread.authorize(creds)
sheet = client.open_by_url(url)
flag = True
i = 0
while flag:
try:
ith = sheet.get_worksheet(i)
i += 1
print(ith)
except Exception as e:
print(e)
flag = False
print(f'Total worksheet = {i}')
# Output:
# ---------------------------
# <Worksheet 'Form Responses 1' id:30127793>
# <Worksheet 'Sheet2' id:1033101728>
# index 2 not found
# Total worksheet = 2