File size: 1,963 Bytes
b23cb24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import json
from apify_client import ApifyClient

def convert_cookies_to_apify(cookies_txt_path):
    cookies = []
    try:
        with open(cookies_txt_path, 'r') as f:
            for line in f:
                if not line.strip() or line.startswith('#'):
                    continue
                parts = line.strip().split('\t')
                if len(parts) >= 7:
                    cookie = {
                        "domain": parts[0],
                        "httpOnly": parts[1] == "TRUE",
                        "path": parts[2],
                        "secure": parts[3] == "TRUE",
                        "expires": int(parts[4]) if parts[4].isdigit() else 0,
                        "name": parts[5],
                        "value": parts[6]
                    }
                    cookies.append(cookie)
    except Exception as e:
        print(f"Error reading cookies: {e}")
    return cookies

client = ApifyClient("apify_api_fKPm5qA9w1u7Gy00uWdJenHks0mCvj2rFeg5")
cookies = convert_cookies_to_apify("cookies.txt")

run_input = {
    "directUrls": ["https://www.instagram.com/p/DVgO7VqlbyC/"],
    "resultsType": "details",
    "proxyConfiguration": {
        "useApifyProxy": True,
        "apifyProxyGroups": ["RESIDENTIAL"]
    }
}

if cookies:
    # Most Apify Instagram scrapers don't take raw cookies but take a 'sessionEncoding'
    # For now let's just try to see if it works without for this specific actor
    # Actually let's just try to find an actor that TRULY downloads media.
    pass

print("Running Apify Actor apify/instagram-scraper...")
run = client.actor("apify/instagram-scraper").call(run_input=run_input)

print("Fetching results...")
items = list(client.dataset(run["defaultDatasetId"]).iterate_items())
if items:
    with open("apify_debug_final.json", "w", encoding="utf-8") as f:
        json.dump(items[0], f, indent=2)
    print("Saved results to apify_debug_final.json")
else:
    print("No items found.")