Historia Para Gandules uses Instaloader, a Python library, to automatically scrape video content from the @historiaparagandules Instagram account. The scraper collects metadata, engagement metrics, and video information for analysis and visualization.
The main scraping script (scraping5.py) performs the following operations:
scraping5.py
import instaloaderimport csv# Create Instaloader instanceL = instaloader.Instaloader()# Target Instagram profileprofile_name = "historiaparagandules"profile = instaloader.Profile.from_username(L.context, profile_name)# Open CSV file for writingwith open("informacion_reels_simple.csv", mode="w", newline="", encoding="utf-8") as file: writer = csv.writer(file) # Write CSV headers writer.writerow(["Fecha", "Texto del reel", "Likes", "Comentarios", "URL del video", "Visualizaciones", "Duración del video (s)", "URL del Post"]) # Iterate through posts and filter videos for post in profile.get_posts(): if post.is_video: fecha = post.date.strftime('%Y-%m-%d %H:%M:%S') texto = post.caption or "Sin texto" likes = post.likes or 0 comentarios = post.comments or 0 url_video = post.video_url or "Sin URL" visualizaciones = post.video_view_count or "No disponible" duracion_video = post.video_duration or "No disponible" url_post = f"https://www.instagram.com/p/{post.shortcode}/" writer.writerow([fecha, texto, likes, comentarios, url_video, visualizaciones, duracion_video, url_post]) print(f"Scrapeando post del {fecha}")print("Información guardada en 'informacion_reels_simple.csv'")
The scraper generates a CSV file (informacion_reels_simple.csv) with UTF-8 encoding:
Fecha,Texto del reel,Likes,Comentarios,URL del video,Visualizaciones,Duración del video (s),URL del Post2024-01-15 14:30:00,"Historical content about...",1250,45,https://...,15000,45.5,https://www.instagram.com/p/ABC123/