def get_image_from_url(url):
session = requests.session()
request = session.get(url=url, headers=headers)
if request.status_code == 200:
soup = bs(request.content, 'lxml')
try:
soup = str(soup)
index = soup.find("accessibility_caption")
soup = soup[index-1000:index]
end = soup.rfind('\",\"')
start = soup.rfind('{') + 8
link = soup[start:end]
link = link.replace('\\u0026', '&')
img = requests.get(link)
except Exception as e:
print(e)
else:
print(request.status_code)
print('ERROR')
return img.content