V
V
Vladimir Vladimirovich2020-07-14 10:14:35
Python
Vladimir Vladimirovich, 2020-07-14 10:14:35

How to parse multiple photos/videos in one Instagram post?

Hello!
My task is to get pictures from any Instagram post.
I managed to make it so that you can get only one picture, in posts where there are several photos / videos, I only get a link to the first picture.
Here is the code:

from bs4 import BeautifulSoup as BS
import requests

URL = 'https://www.instagram.com/p/B89F_agFwrF/'

r = requests.get(URL)
soup = BS(r.content, 'html.parser')
link = soup.find('meta', {'property': 'og:image'}).get('content')

print(link)


I don’t know how correct this code is.
If there are people here who know how to solve my problem, I will be very grateful.
PS if the solution turns out to be simple, sorry, I'm still a novice in this matter

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Puma Thailand, 2020-07-14
@opium

so they are all sent in json to the post sequentially, take it and parse it, what is the actual problem of collecting them?

F
FANTASANTA, 2020-07-20
@FANTASANTA

You need to parse this json data:

https://www.instagram.com/graphql/query/?query_hash=5789ea2c88978c55ccd762cb99e7b8bf&variables={"shortcode":"B_8MQ67h-mf"}

- pass the post code to the shortcode parameter.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question