import requests
import re

url = "https://www.instagram.com/p/DVOazPSjJQm/embed"
print(f"Fetching {url}")
res = requests.get(url, headers={'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'})
html = res.text

# Try to find likes
like_pattern = r'likeCountClick[^>]*>([\d,]+)\s*likes?<'
m = re.search(like_pattern, html, re.IGNORECASE)
if m:
    print(f"Likes found: {m.group(1)}")
else:
    print("Like pattern not found")
    
# Try to find comments
cmt_pattern = r'commentCountClick[^>]*>([\d,]+)\s*comments?<'
m = re.search(cmt_pattern, html, re.IGNORECASE)
if m:
    print(f"Comments found: {m.group(1)}")
else:
    print("Comment pattern not found")
    
# dump first 5000 chars of related area
idx = html.find('likeCountClick')
if idx != -1:
    print("--- HTML SNIPPET AROUND LIKES ---")
    start = max(0, idx - 200)
    print(html[start:start+1000])

idx = html.find('Comment')
if idx != -1:
    print("--- HTML SNIPPET AROUND COMMENTS ---")
    start = max(0, idx - 200)
    print(html[start:start+1000])
