[Python] Get Monthly Views of Pinterest accounts using Python script code

Discussão em 'Python' iniciado por Stack, Maio 25, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to get the monthly views of some of the pinterest accounts that I track on regular bases using my own code.

    Since Pinterest doesn't show the monthly views of business accounts publicly, does anybody here know how should I get the monthly views of business accounts using code (python).

    I wonder how do softwares like Pinclicks and Pin Inspector are able to get these monthly views numbers without us providing our Pinterest login details to these softwares.

    What I have written so far is selinium code in Python that opens the browser, logs in to a dummy account and gets the monthly views. This is bound to get my dummy account banned for bot behavior so I am looking for some other better method.

    import time
    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.common.keys import Keys
    from selenium.webdriver.chrome.service import Service

    # ---------------------- CONFIGURATION ----------------------
    DUMMY_EMAIL = ''
    DUMMY_PASSWORD = ''
    CHROMEDRIVER_PATH = 'chromedriver.exe' # Adjust path if needed

    PROFILES_FILE = 'profiles.txt' # Each line: https://www.pinterest.com/username/
    # ----------------------------------------------------------

    def pinterest_login(driver, email, password):
    driver.get("https://www.pinterest.com/login/")
    time.sleep(2)
    email_box = driver.find_element(By.NAME, 'id')
    email_box.clear()
    email_box.send_keys(email)
    time.sleep(1)

    password_box = driver.find_element(By.NAME, 'password')
    password_box.clear()
    password_box.send_keys(password)
    time.sleep(1)
    password_box.send_keys(Keys.RETURN)
    time.sleep(5) # Wait for login

    def get_monthly_views(driver, profile_url):
    driver.get(profile_url)
    time.sleep(4) # Wait for page to load

    monthly_views = "NOT FOUND"
    try:
    # Try the standard XPATH for "monthly views"
    views_element = driver.find_element(By.XPATH, '//div[contains(text(), "monthly views")]')
    monthly_views = views_element.text
    except Exception:
    # Sometimes the format is like "167.2k monthly views"
    try:
    views_element = driver.find_element(By.XPATH, '//span[contains(text(), "monthly views")]')
    monthly_views = views_element.text
    except Exception:
    monthly_views = "NOT FOUND"
    return monthly_views

    def main():
    # Start browser
    service = Service(CHROMEDRIVER_PATH)
    driver = webdriver.Chrome(service=service)
    try:
    # Step 1: Login to Pinterest with dummy account
    pinterest_login(driver, DUMMY_EMAIL, DUMMY_PASSWORD)
    print("Logged in successfully!")

    # Step 2: Read all profile URLs
    with open(PROFILES_FILE, "r") as f:
    profile_urls = [line.strip() for line in f if line.strip()]

    # Step 3: Loop through all profiles and get monthly views
    for url in profile_urls:
    views = get_monthly_views(driver, url)
    print(f"{url}: {views}")

    finally:
    driver.quit()

    if __name__ == "__main__":
    main()

    Continue reading...

Compartilhe esta Página