I have an Instagram URL:
https://www.instagram.com/p/B2EtjT9hgvG/
the image inside has that URL:
if I have only Instagram URL is possible to get image URL with an API or something else?
Thanks to the help of @Chris Doyle I can give you a little help using selenium
:
from selenium import webdriver
driver = webdriver.Chrome('chromedriver.exe')
driver.get('https://www.instagram.com/p/B2EtjT9hgvG/')
metas = driver.find_elements_by_tag_name('meta')
for elem in metas:
if elem.get_attribute('property') == 'og:image':
print(elem.get_attribute('content'))
or with requests
and bs4
accordingly:
import requests
from bs4 import BeautifulSoup
result = requests.get("https://www.instagram.com/p/B2EtjT9hgvG/")
c = result.content
soup = BeautifulSoup(c)
metas = soup.find_all(attrs={"property": "og:image"})
print(metas[0].attrs['content'])