creat a script script python to display the insta view/like/ratio count in python

To display the Instagram view/like/ratio count using Python, you can create a script that performs web scraping to extract the required information and then use data visualization libraries to display the counts.

Here's an example script using Python, BeautifulSoup for web scraping, and Matplotlib for data visualization:

main.py
import requests
from bs4 import BeautifulSoup
import matplotlib.pyplot as plt

# Function to scrape Instagram counts
def scrape_instagram_counts(username):
    url = f"https://www.instagram.com/{username}"
    response = requests.get(url)
    if response.status_code == 200:
        soup = BeautifulSoup(response.content, 'html.parser')
        follower_count = soup.find('meta', property='og:description').get('content')
        views_count = soup.find('script', string=lambda x: 'edge_media_preview_like_count' in str(x)).get_text()
        like_ratio = int(views_count) / int(follower_count.split()[0].replace(',', ''))
        return int(follower_count.split()[0].replace(',', '')), int(views_count), like_ratio
    else:
        return None

# Input your Instagram username here
username = 'your_instagram_username'
counts = scrape_instagram_counts(username)

if counts:
    follower_count, views_count, like_ratio = counts
    print(f'Instagram Stats for {username}:')
    print(f'Followers: {follower_count}')
    print(f'Views: {views_count}')
    print(f'Like Ratio: {like_ratio:.2f}')
    
    # Data Visualization
    labels = ['Followers', 'Views']
    values = [follower_count, views_count]
    
    plt.bar(labels, values)
    plt.xlabel('Count Type')
    plt.ylabel('Count')
    plt.title(f'Instagram Stats for {username}')
    plt.show()
else:
    print(f'Unable to retrieve Instagram stats for {username}. Please check the username or try again later.')
1471 chars
40 lines

Make sure to replace 'your_instagram_username' with your actual Instagram username. The script will scrape the follower count, views count, and calculate the like ratio using the provided username. It will print the stats and display a bar chart using Matplotlib.

Note: Keep in mind that web scraping may violate the terms of service of some websites, so make sure you comply with the rules and regulations of the websites you are scraping.

gistlibby LogSnag