[Python] How can I extract the caption/description from a single Instagram post URL in Python?

Discussão em 'Python' iniciado por Stack, Setembro 1, 2025.

  1. Stack

    Stack Membro Participativo

    I’m trying to write a simple program that can take one Instagram post link and extract the caption/description of that particular post.

    For example, given a link like:

    https://www.instagram.com/p/POST_ID/

    I want to get the caption text (not images, not comments, just the post description).

    My requirements:

    I only need to do this one post at a time (not bulk scraping).

    I don’t need comments, likes, or media — only the caption/description.

    A simple solution in Python (preferred) is fine.

    My questions:

    Is there a straightforward way (API, library, or parsing method) to fetch the caption from a single Instagram post link?

    Do I need to use the official Instagram Graph API, or is there a simpler approach for just reading captions one by one?

    I tried fetching the page source and parsing it with BeautifulSoup:

    url = "https://www.instagram.com/p/POST_ID/"
    response = requests.get(url)
    soup = BeautifulSoup(response.text, "html.parser")

    print(soup.prettify()) # trying to find where the caption is


    import requests from bs4 import BeautifulSoup

    But I couldn’t locate the caption in the raw HTML. It looks like the data might be hidden inside JavaScript or requires an API.

    Continue reading...

Compartilhe esta Página