links = "http://www.website_name.com/"
content_ig = BeautifulSoup(send.content, 'html.parser')
script = content_ig.find_all("script")[3].get_text()
script = script.split('openData = ')[1][:-1]
if not script:
#This condition i create to next if the value is out of index
else:
print("Works")
try:
script = script.split('openData = ')[1][:-1]
print("Works")
except IndexError:
... # code to run if the value is out of index
In [1739]: x = [0]
In [1740]: try:
...: print(x[1]) # only 1 element in x, so this is invalid
...: except IndexError:
...: print("List out of range!")
...:
List out of range!