from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
import time

url = "https://www.instagram.com/p/DVOazPSjJQm/"

options = Options()
options.add_argument("--headless=new")
options.add_argument("--disable-gpu")
options.add_argument("--window-size=1200,900")
# Add a realistic user agent
options.add_argument("--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36")

print("Starting driver...")
driver = webdriver.Chrome(options=options)
try:
    driver.get(url)
    print("Wait 6s...")
    time.sleep(6)
    
    html = driver.page_source
    print(f"HTML length: {len(html)}")
    
    # Try the user's specific class
    try:
        spans = driver.find_elements(By.XPATH, "//span[@class='x1ypdohk x1s688f x2fvf9 xe9ewy2' and @role='button']")
        print(f"Found {len(spans)} spans with exact class.")
        for s in spans:
            print(f"Span text: {s.text}")
    except Exception as e:
        print(f"Xpath failed: {e}")
        
    # See if login wall is present
    if "Log In" in html or "Sign Up" in html or "login" in driver.current_url.lower():
        print("LOGIN WALL DETECTED")
        
    driver.save_screenshot("test_scrape.png")
    print("Saved screenshot to test_scrape.png")
finally:
    driver.quit()
