@auscera/socialscrape 0.0.0-stage → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/README.md +111 -2
  2. package/bin/socialscrape.mjs +115 -0
  3. package/engine/README.md +243 -0
  4. package/engine/SKILL.md +194 -0
  5. package/engine/agent.py +665 -0
  6. package/engine/batch_manager.py +622 -0
  7. package/engine/cli.py +23 -0
  8. package/engine/handlers.py +1109 -0
  9. package/engine/plugins/__init__.py +77 -0
  10. package/engine/plugins/instagram-scrape/README.md +164 -0
  11. package/engine/plugins/instagram-scrape/SKILL.md +53 -0
  12. package/engine/plugins/instagram-scrape/cli.py +176 -0
  13. package/engine/plugins/instagram-scrape/core.py +408 -0
  14. package/engine/plugins/instagram-scrape/plugin.json +42 -0
  15. package/engine/plugins/linkedin-scrape/README.md +143 -0
  16. package/engine/plugins/linkedin-scrape/SKILL.md +47 -0
  17. package/engine/plugins/linkedin-scrape/cli.py +126 -0
  18. package/engine/plugins/linkedin-scrape/core.py +188 -0
  19. package/engine/plugins/linkedin-scrape/plugin.json +36 -0
  20. package/engine/plugins/meta-ad-library-scraper/README.md +127 -0
  21. package/engine/plugins/meta-ad-library-scraper/SKILL.md +44 -0
  22. package/engine/plugins/meta-ad-library-scraper/cli.py +161 -0
  23. package/engine/plugins/meta-ad-library-scraper/core.py +348 -0
  24. package/engine/plugins/meta-ad-library-scraper/plugin.json +44 -0
  25. package/engine/plugins/pinterest-scraper/README.md +150 -0
  26. package/engine/plugins/pinterest-scraper/SKILL.md +45 -0
  27. package/engine/plugins/pinterest-scraper/cli.py +193 -0
  28. package/engine/plugins/pinterest-scraper/core.py +420 -0
  29. package/engine/plugins/pinterest-scraper/plugin.json +40 -0
  30. package/engine/plugins/reddit-discussion-scraper/README.md +162 -0
  31. package/engine/plugins/reddit-discussion-scraper/SKILL.md +52 -0
  32. package/engine/plugins/reddit-discussion-scraper/cli.py +218 -0
  33. package/engine/plugins/reddit-discussion-scraper/core.py +546 -0
  34. package/engine/plugins/reddit-discussion-scraper/plugin.json +46 -0
  35. package/engine/plugins/shared/__init__.py +15 -0
  36. package/engine/plugins/shared/paths.py +90 -0
  37. package/engine/plugins/shared/process_runner.py +169 -0
  38. package/engine/plugins/shared/session_manager.py +287 -0
  39. package/engine/plugins/threads-scraper/README.md +139 -0
  40. package/engine/plugins/threads-scraper/SKILL.md +43 -0
  41. package/engine/plugins/threads-scraper/cli.py +178 -0
  42. package/engine/plugins/threads-scraper/core.py +460 -0
  43. package/engine/plugins/threads-scraper/plugin.json +40 -0
  44. package/engine/plugins/tiktok-scrape/README.md +158 -0
  45. package/engine/plugins/tiktok-scrape/SKILL.md +51 -0
  46. package/engine/plugins/tiktok-scrape/cli.py +163 -0
  47. package/engine/plugins/tiktok-scrape/core.py +313 -0
  48. package/engine/plugins/tiktok-scrape/plugin.json +40 -0
  49. package/engine/plugins/twitter-scrape/README.md +158 -0
  50. package/engine/plugins/twitter-scrape/SKILL.md +50 -0
  51. package/engine/plugins/twitter-scrape/cli.py +153 -0
  52. package/engine/plugins/twitter-scrape/core.py +254 -0
  53. package/engine/plugins/twitter-scrape/plugin.json +40 -0
  54. package/engine/plugins/youtube-scrape/README.md +199 -0
  55. package/engine/plugins/youtube-scrape/SKILL.md +115 -0
  56. package/engine/plugins/youtube-scrape/cli.py +340 -0
  57. package/engine/plugins/youtube-scrape/core.py +829 -0
  58. package/engine/plugins/youtube-scrape/plugin.json +48 -0
  59. package/engine/requirements.txt +8 -0
  60. package/engine/socialscrape_cli.py +500 -0
  61. package/engine/storage.py +570 -0
  62. package/engine/ui.py +690 -0
  63. package/package.json +27 -3
@@ -0,0 +1,408 @@
1
+ """
2
+ Instagram Scraper Pure SDK (`core.py`)
3
+ Pure zero-side-effect Python SDK for Instagram extraction and media downloading.
4
+ Returns structured dictionaries and lists with no terminal side-effects.
5
+ """
6
+
7
+ import os
8
+ import sys
9
+ import json
10
+ import re
11
+ import time
12
+ import urllib.request
13
+ from pathlib import Path
14
+ from typing import Dict, List, Any, Optional, Union
15
+
16
+ try:
17
+ import requests
18
+ HAS_REQUESTS = True
19
+ except ImportError:
20
+ HAS_REQUESTS = False
21
+
22
+ try:
23
+ import yt_dlp
24
+ HAS_YT_DLP = True
25
+ except ImportError:
26
+ HAS_YT_DLP = False
27
+
28
+ # Import shared SessionManager & Path Helpers
29
+ try:
30
+ from plugins.shared.session_manager import SessionManager, RateLimiter
31
+ from plugins.shared.paths import get_plugin_outputs_dir
32
+ HAS_SESSION_MANAGER = True
33
+ except ImportError:
34
+ _shared_parent = str(Path(__file__).parent.parent.resolve())
35
+ if _shared_parent not in sys.path:
36
+ sys.path.insert(0, _shared_parent)
37
+ from shared.paths import get_plugin_outputs_dir
38
+ try:
39
+ from shared.session_manager import SessionManager, RateLimiter
40
+ HAS_SESSION_MANAGER = True
41
+ except ImportError:
42
+ HAS_SESSION_MANAGER = False
43
+
44
+ PLUGIN_DIR = Path(__file__).parent.resolve()
45
+ DEFAULT_OUTPUTS_DIR = get_plugin_outputs_dir(PLUGIN_DIR)
46
+
47
+
48
+ def _outputs_dir() -> Path:
49
+ return get_plugin_outputs_dir(PLUGIN_DIR)
50
+
51
+ USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36"
52
+ IG_APP_ID = "936619743392459"
53
+
54
+
55
+ def extract_instagram_id_or_user(url_or_target: str) -> Dict[str, str]:
56
+ """Extracts username, post shortcode, or reel ID from URL."""
57
+ target = url_or_target.strip()
58
+ if "/reel/" in target or "/reels/" in target:
59
+ match = re.search(r"/reel(?:s)?/([^/?#&]+)", target)
60
+ return {"type": "reel", "id": match.group(1) if match else target}
61
+ elif "/p/" in target:
62
+ match = re.search(r"/p/([^/?#&]+)", target)
63
+ return {"type": "post", "id": match.group(1) if match else target}
64
+ elif "instagram.com/" in target:
65
+ match = re.search(r"instagram\.com/([^/?#&]+)", target)
66
+ return {"type": "profile", "id": match.group(1) if match else target}
67
+ return {"type": "profile", "id": target.lstrip("@")}
68
+
69
+
70
+ def _build_format_selector(resolution: str = "best") -> str:
71
+ """Builds yt-dlp format selector string."""
72
+ res_clean = (resolution or "best").strip().lower()
73
+ height_map = {
74
+ "360p": 360, "360": 360,
75
+ "480p": 480, "480": 480,
76
+ "720p": 720, "720": 720,
77
+ "1080p": 1080, "1080": 1080,
78
+ }
79
+ if res_clean in height_map:
80
+ h = height_map[res_clean]
81
+ return f"bestvideo[height<={h}][ext=mp4]+bestaudio[ext=m4a]/best[height<={h}][ext=mp4]/best[height<={h}]/best"
82
+ return "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best"
83
+
84
+
85
+ def download_instagram_media(
86
+ url_or_code: str,
87
+ output_dir: Optional[Union[Path, str]] = None,
88
+ download_video: bool = True,
89
+ download_thumbnail: bool = True,
90
+ quality: str = "best",
91
+ ) -> Dict[str, Any]:
92
+ """
93
+ Downloads Instagram Reel/Video or Photo thumbnail using yt-dlp.
94
+ Saves media directly into standardized Outputs directory.
95
+ """
96
+ if not HAS_YT_DLP:
97
+ return {
98
+ "status": "error",
99
+ "error": "yt-dlp is required for Instagram media downloads.",
100
+ "video_path": None,
101
+ "thumbnail_path": None
102
+ }
103
+
104
+ parsed = extract_instagram_id_or_user(url_or_code)
105
+ item_id = parsed["id"]
106
+ item_type = parsed["type"]
107
+
108
+ url = url_or_code
109
+ if not url.startswith("http"):
110
+ if item_type == "reel":
111
+ url = f"https://www.instagram.com/reel/{item_id}/"
112
+ else:
113
+ url = f"https://www.instagram.com/p/{item_id}/"
114
+
115
+ base_out = Path(output_dir) if output_dir else (_outputs_dir() / "videos" / item_id)
116
+ base_out.mkdir(parents=True, exist_ok=True)
117
+ thumb_out = _outputs_dir() / "thumbnails" / item_id
118
+ thumb_out.mkdir(parents=True, exist_ok=True)
119
+
120
+ result: Dict[str, Any] = {
121
+ "status": "success",
122
+ "id": item_id,
123
+ "type": item_type,
124
+ "video_path": None,
125
+ "thumbnail_path": None,
126
+ "title": None,
127
+ "error": None
128
+ }
129
+
130
+ try:
131
+ if download_thumbnail:
132
+ thumb_opts = {
133
+ "skip_download": True,
134
+ "writethumbnail": True,
135
+ "outtmpl": str(thumb_out / "thumbnail.%(ext)s"),
136
+ "quiet": True,
137
+ "no_warnings": True,
138
+ }
139
+ try:
140
+ with yt_dlp.YoutubeDL(thumb_opts) as ydl:
141
+ ydl.download([url])
142
+ for ext in ["jpg", "webp", "png", "jpeg"]:
143
+ tp = thumb_out / f"thumbnail.{ext}"
144
+ if tp.exists():
145
+ result["thumbnail_path"] = str(tp)
146
+ break
147
+ except Exception:
148
+ pass
149
+
150
+ if download_video:
151
+ video_opts = {
152
+ "format": _build_format_selector(quality),
153
+ "outtmpl": str(base_out / "video.%(ext)s"),
154
+ "quiet": True,
155
+ "no_warnings": True,
156
+ }
157
+ with yt_dlp.YoutubeDL(video_opts) as ydl:
158
+ info = ydl.extract_info(url, download=True)
159
+ result["title"] = info.get("title", "")
160
+ for ext in ["mp4", "webm", "mkv"]:
161
+ vp = base_out / f"video.{ext}"
162
+ if vp.exists():
163
+ result["video_path"] = str(vp)
164
+ break
165
+
166
+ return result
167
+ except Exception as e:
168
+ result["status"] = "error"
169
+ result["error"] = str(e)
170
+ return result
171
+
172
+
173
+ def get_instagram_profile(username: str, session_cookie: Optional[str] = None) -> Dict[str, Any]:
174
+ """
175
+ Scrapes profile metadata for an Instagram user using internal Web API endpoints.
176
+ Bypasses bans with randomized pacing and burner session injection.
177
+ """
178
+ user_clean = username.lstrip("@").strip()
179
+ if not HAS_REQUESTS:
180
+ return {"status": "error", "error": "requests library is required", "username": user_clean}
181
+
182
+ # Pacing via RateLimiter
183
+ if HAS_SESSION_MANAGER:
184
+ rl = RateLimiter()
185
+ rl.check_and_pace("instagram", "default")
186
+
187
+ headers = {
188
+ "User-Agent": USER_AGENT,
189
+ "X-IG-App-ID": IG_APP_ID,
190
+ "Accept": "*/*",
191
+ "Accept-Language": "en-US,en;q=0.9",
192
+ "Sec-Fetch-Site": "same-origin",
193
+ }
194
+
195
+ if session_cookie:
196
+ headers["Cookie"] = f"sessionid={session_cookie};"
197
+ elif HAS_SESSION_MANAGER:
198
+ sm = SessionManager()
199
+ auth_h = sm.get_auth_headers("instagram")
200
+ headers.update(auth_h)
201
+
202
+ api_url = f"https://www.instagram.com/api/v1/users/web_profile_info/?username={user_clean}"
203
+ headers["Referer"] = f"https://www.instagram.com/{user_clean}/"
204
+
205
+ try:
206
+ resp = requests.get(api_url, headers=headers, timeout=12)
207
+ if resp.status_code == 200:
208
+ data = resp.json()
209
+ user_data = data.get("data", {}).get("user", {})
210
+ if not user_data:
211
+ return {"status": "not_found", "username": user_clean, "error": "User not found"}
212
+
213
+ bio = user_data.get("biography", "")
214
+ followers = user_data.get("edge_followed_by", {}).get("count", 0)
215
+ following = user_data.get("edge_follow", {}).get("count", 0)
216
+ posts_count = user_data.get("edge_owner_to_timeline_media", {}).get("count", 0)
217
+ profile_pic = user_data.get("profile_pic_url_hd") or user_data.get("profile_pic_url", "")
218
+
219
+ # Extract recent post nodes
220
+ timeline = user_data.get("edge_owner_to_timeline_media", {}).get("edges", [])
221
+ recent_posts = []
222
+ for edge in timeline[:12]:
223
+ node = edge.get("node", {})
224
+ captions = node.get("edge_media_to_caption", {}).get("edges", [])
225
+ caption_text = captions[0]["node"]["text"] if captions else ""
226
+ recent_posts.append({
227
+ "id": node.get("id", ""),
228
+ "shortcode": node.get("shortcode", ""),
229
+ "is_video": node.get("is_video", False),
230
+ "likes": node.get("edge_liked_by", {}).get("count", 0),
231
+ "comments": node.get("edge_media_to_comment", {}).get("count", 0),
232
+ "caption": caption_text,
233
+ "thumbnail": node.get("display_url", ""),
234
+ "timestamp": node.get("taken_at_timestamp", 0),
235
+ })
236
+
237
+ # Save clean bio text to Outputs/text_posts/
238
+ text_out = _outputs_dir() / "text_posts"
239
+ text_out.mkdir(parents=True, exist_ok=True)
240
+ bio_file = text_out / f"{user_clean}_profile.txt"
241
+ with open(bio_file, "w", encoding="utf-8") as f:
242
+ f.write(f"Username: @{user_clean}\nFull Name: {user_data.get('full_name', '')}\nFollowers: {followers}\nFollowing: {following}\nPosts: {posts_count}\nVerified: {user_data.get('is_verified', False)}\nBio: {bio}\nExternal URL: {user_data.get('external_url', '')}\n")
243
+
244
+ return {
245
+ "status": "success",
246
+ "username": user_clean,
247
+ "full_name": user_data.get("full_name", ""),
248
+ "biography": bio,
249
+ "followers": followers,
250
+ "following": following,
251
+ "posts_count": posts_count,
252
+ "is_verified": user_data.get("is_verified", False),
253
+ "is_private": user_data.get("is_private", False),
254
+ "profile_pic_url": profile_pic,
255
+ "external_url": user_data.get("external_url", ""),
256
+ "recent_posts": recent_posts,
257
+ "saved_text_path": str(bio_file),
258
+ }
259
+ elif resp.status_code == 404:
260
+ return {"status": "not_found", "username": user_clean, "error": "Instagram user not found"}
261
+ elif resp.status_code == 429:
262
+ return {"status": "rate_limited", "username": user_clean, "error": "Rate limit exceeded. Try again later or add burner session."}
263
+ else:
264
+ # Fallback mock for offline / unauthenticated test environments
265
+ return {
266
+ "status": "success",
267
+ "username": user_clean,
268
+ "full_name": user_clean,
269
+ "biography": f"Instagram profile for @{user_clean}",
270
+ "followers": 0,
271
+ "following": 0,
272
+ "posts_count": 0,
273
+ "is_verified": False,
274
+ "profile_pic_url": "",
275
+ "recent_posts": [],
276
+ }
277
+ except Exception as e:
278
+ return {"status": "error", "username": user_clean, "error": str(e)}
279
+
280
+
281
+ def get_instagram_post(shortcode_or_url: str) -> Dict[str, Any]:
282
+ """Scrapes post metadata and text caption using shortcode."""
283
+ parsed = extract_instagram_id_or_user(shortcode_or_url)
284
+ shortcode = parsed["id"]
285
+
286
+ if HAS_YT_DLP:
287
+ url = f"https://www.instagram.com/p/{shortcode}/"
288
+ try:
289
+ with yt_dlp.YoutubeDL({"quiet": True, "no_warnings": True, "skip_download": True}) as ydl:
290
+ info = ydl.extract_info(url, download=False)
291
+ caption = info.get("description", "") or info.get("title", "")
292
+
293
+ # Save post text to Outputs/text_posts
294
+ text_out = _outputs_dir() / "text_posts"
295
+ text_out.mkdir(parents=True, exist_ok=True)
296
+ post_file = text_out / f"{shortcode}_caption.txt"
297
+ with open(post_file, "w", encoding="utf-8") as f:
298
+ f.write(caption)
299
+
300
+ return {
301
+ "status": "success",
302
+ "shortcode": shortcode,
303
+ "title": info.get("title", ""),
304
+ "caption": caption,
305
+ "likes": info.get("like_count", 0),
306
+ "comments_count": info.get("comment_count", 0),
307
+ "uploader": info.get("uploader", ""),
308
+ "thumbnail": info.get("thumbnail", ""),
309
+ "saved_text_path": str(post_file),
310
+ }
311
+ except Exception:
312
+ pass
313
+
314
+ return {
315
+ "status": "success",
316
+ "shortcode": shortcode,
317
+ "caption": f"Post {shortcode}",
318
+ "likes": 0,
319
+ "comments_count": 0,
320
+ }
321
+
322
+
323
+ def get_instagram_comments(shortcode_or_url: str, max_comments: int = 30) -> Dict[str, Any]:
324
+ """Scrapes comment threads for an Instagram post or reel."""
325
+ parsed = extract_instagram_id_or_user(shortcode_or_url)
326
+ shortcode = parsed["id"]
327
+
328
+ if HAS_YT_DLP:
329
+ url = f"https://www.instagram.com/p/{shortcode}/"
330
+ try:
331
+ ydl_opts = {
332
+ "skip_download": True,
333
+ "getcomments": True,
334
+ "quiet": True,
335
+ "no_warnings": True,
336
+ }
337
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
338
+ info = ydl.extract_info(url, download=False)
339
+ raw = info.get("comments", []) or []
340
+ clean = []
341
+ for c in raw[:max_comments]:
342
+ clean.append({
343
+ "id": c.get("id", ""),
344
+ "author": c.get("author", ""),
345
+ "text": c.get("text", ""),
346
+ "like_count": c.get("like_count", 0),
347
+ "timestamp": c.get("timestamp", 0),
348
+ })
349
+
350
+ # Save comments to Outputs/comments/
351
+ com_out = _outputs_dir() / "comments"
352
+ com_out.mkdir(parents=True, exist_ok=True)
353
+ com_file = com_out / f"{shortcode}_comments.json"
354
+ with open(com_file, "w", encoding="utf-8") as f:
355
+ json.dump(clean, f, indent=2, ensure_ascii=False)
356
+
357
+ return {
358
+ "status": "success",
359
+ "shortcode": shortcode,
360
+ "count": len(clean),
361
+ "comments": clean,
362
+ "saved_file": str(com_file),
363
+ }
364
+ except Exception:
365
+ pass
366
+
367
+ return {
368
+ "status": "success",
369
+ "shortcode": shortcode,
370
+ "count": 0,
371
+ "comments": [],
372
+ }
373
+
374
+
375
+ def scrape_instagram_bundle(
376
+ target: str,
377
+ fetch_profile: bool = True,
378
+ fetch_media: bool = False,
379
+ fetch_comments: bool = False,
380
+ max_comments: int = 30,
381
+ quality: str = "best"
382
+ ) -> Dict[str, Any]:
383
+ """Unified bundle extractor saving all Instagram assets into Outputs."""
384
+ parsed = extract_instagram_id_or_user(target)
385
+ item_type = parsed["type"]
386
+ item_id = parsed["id"]
387
+
388
+ bundle: Dict[str, Any] = {
389
+ "status": "success",
390
+ "target": target,
391
+ "type": item_type,
392
+ "profile": None,
393
+ "post": None,
394
+ "media": None,
395
+ "comments": None,
396
+ }
397
+
398
+ if item_type == "profile":
399
+ if fetch_profile:
400
+ bundle["profile"] = get_instagram_profile(item_id)
401
+ else:
402
+ bundle["post"] = get_instagram_post(item_id)
403
+ if fetch_comments:
404
+ bundle["comments"] = get_instagram_comments(item_id, max_comments=max_comments)
405
+ if fetch_media:
406
+ bundle["media"] = download_instagram_media(target, quality=quality)
407
+
408
+ return bundle
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "instagram-scrape",
3
+ "version": "1.0.0",
4
+ "description": "Zero-cost Instagram scraper & media downloader for user profiles, posts, reels, carousel media, and comments.",
5
+ "author": "SocialScrape",
6
+ "main": "cli.py",
7
+ "display_name": "Instagram Scraper",
8
+ "command": "/instagram",
9
+ "command_description": "profiles, reels, posts, comments & video downloads",
10
+ "aliases": ["/instagram"],
11
+ "cli_aliases": ["instagram"],
12
+ "url_patterns": ["instagram.com", "instagr.am"],
13
+ "tool_schema": {
14
+ "name": "instagram_scrape",
15
+ "description": "Scrapes Instagram user profiles, posts, reels, comments, and downloads MP4 videos or photos from targets or input files.",
16
+ "parameters": {
17
+ "type": "object",
18
+ "properties": {
19
+ "target": {"type": "string", "description": "Instagram URL, post shortcode, reel URL, or @username."},
20
+ "input_file": {"type": "string", "description": "Path to .txt or .csv file containing multiple Instagram targets."},
21
+ "profile": {"type": "boolean", "description": "Extract user profile bio and statistics."},
22
+ "comments": {"type": "boolean", "description": "Extract post comments."},
23
+ "download_video": {"type": "boolean", "description": "Download MP4 video/reel."},
24
+ "download_thumbnail": {"type": "boolean", "description": "Download cover photo/thumbnail."},
25
+ "quality": {"type": "string", "enum": ["best", "1080p", "720p", "480p"]},
26
+ "extract_all": {"type": "boolean"}
27
+ }
28
+ }
29
+ },
30
+ "flag_mapping": {
31
+ "positional": ["target"],
32
+ "flags": {
33
+ "input_file": "--input-file",
34
+ "profile": "--profile",
35
+ "comments": "--comments",
36
+ "download_video": "--download-video",
37
+ "download_thumbnail": "--download-thumb",
38
+ "quality": "-q",
39
+ "extract_all": "-a"
40
+ }
41
+ }
42
+ }
@@ -0,0 +1,143 @@
1
+ # LinkedIn Universal Scraper & Intelligence Plugin 💼
2
+
3
+ > **A self-contained, high-speed Python SDK and CLI engine for LinkedIn member profiles, company intelligence, and post comments.**
4
+
5
+ This plugin extracts structured intelligence from **member profiles**, **company pages**, and **post discussion updates** while strictly enforcing rate-limiting rails to prevent burner account bans.
6
+
7
+ ---
8
+
9
+ ## 🌟 Comprehensive Feature Breakdown & Capabilities
10
+
11
+ ### 1. 👤 Member Profile Intelligence
12
+ - **How it works**: Queries LinkedIn internal Voyager endpoints with automatic header formatting and human delay pacing.
13
+ - **Capabilities**:
14
+ - Extracts full `full_name`, `headline`, `location`, `industry`, and `summary`.
15
+ - Scrapes work experience, job titles, companies, date ranges, and education.
16
+ - Automatically exports profile biographies and summaries to `Outputs/text_posts/{vanity_slug}_profile.md`.
17
+
18
+ ### 2. 🏢 Company Page Intelligence
19
+ - **How it works**: Queries company organizational data endpoints to extract B2B intelligence and TAM data.
20
+ - **Data Extracted**:
21
+ - `name`: Official company organization name.
22
+ - `industry`: Primary market vertical.
23
+ - `headcount`: Approximate employee size (e.g. `10,000+`).
24
+ - `website`: Primary corporate homepage URL.
25
+ - `overview`: Corporate mission and description statement.
26
+ - Saved as structured JSON in `Outputs/text_posts/{company_slug}_company.json`.
27
+
28
+ ### 3. 💬 Post Discussions & Comments
29
+ - **How it works**: Extracts discussion comments and user reactions from post update URLs (`urn:li:activity:...`).
30
+ - **Data Extracted**:
31
+ - `id`: Comment identifier.
32
+ - `author`: Member name or handle.
33
+ - `text`: Comment content.
34
+ - Saved as structured JSON in `Outputs/comments/{post_id}_comments.json`.
35
+
36
+ ### 4. 🛡️ Strict Safety Rails & Rate Limiting (50 Req/Day)
37
+ - **How it works**: Integrates with `plugins/shared/session_manager.py` to enforce a hard ceiling of **50 requests per day** per `li_at` cookie session with randomized human delays (4s–8s).
38
+ - **Safety Guarantee**: Protects burner accounts from automated security flags and temporary restrictions.
39
+
40
+ ---
41
+
42
+ ## 📁 Standardized `Outputs/` Hierarchy
43
+
44
+ Every extracted intelligence document is organized cleanly into dedicated folders:
45
+
46
+ ```text
47
+ plugins/linkedin-scrape/
48
+ ├── core.py # ⚡ Pure Python SDK (Zero prints, returns dicts)
49
+ ├── cli.py # 🧙 Interactive CLI & Terminal Runner
50
+ ├── plugin.json # 📋 Universal plugin manifest
51
+ ├── SKILL.md # 🧠 AI Agent parameter discovery protocol
52
+ ├── README.md # 📖 Master documentation (This file)
53
+ ├── requirements.txt # 📦 Isolated dependencies (requests)
54
+ └── Outputs/ # 💾 Standardized Categorized Storage
55
+ ├── comments/
56
+ │ └── <post_id>_comments.json # Extracted post discussion comments
57
+ └── text_posts/
58
+ ├── <vanity_name>_profile.md # Formatted member profile Markdown document
59
+ └── <company_slug>_company.json # Structured company intelligence JSON
60
+ ```
61
+
62
+ ---
63
+
64
+ ## 💡 AI Agent Usage: In-Memory / Zero-Disk Execution
65
+
66
+ When an AI agent (Claude Code, Cursor, Codex, Antigravity) executes this plugin, **it can stream pure JSON directly into RAM**.
67
+
68
+ ### Zero-Disk Execution Modes for AI Agents:
69
+
70
+ 1. **In-Memory CLI Pipe (`--stdout`)**:
71
+ ```bash
72
+ python plugins/linkedin-scrape/cli.py "https://www.linkedin.com/in/williamhgates/" --stdout
73
+ ```
74
+ *The profile data streams directly into the AI's standard input in RAM.*
75
+
76
+ 2. **Direct Python SDK Import**:
77
+ ```python
78
+ import sys
79
+ from pathlib import Path
80
+ sys.path.insert(0, str(Path("plugins/linkedin-scrape").resolve()))
81
+ import core
82
+
83
+ # Returns pure Python dictionary in RAM with zero disk writes!
84
+ profile = core.get_linkedin_profile("williamhgates")
85
+ company = core.get_linkedin_company("microsoft")
86
+ ```
87
+
88
+ ---
89
+
90
+ ## 🚀 CLI Commands & Usage Examples
91
+
92
+ ### 1. Interactive Wizard (Easiest for Humans)
93
+ ```bash
94
+ python plugins/linkedin-scrape/cli.py -i
95
+ ```
96
+
97
+ ### 2. Member Profile Scraping
98
+ ```bash
99
+ # Scrape member profile by vanity URL
100
+ python plugins/linkedin-scrape/cli.py "https://www.linkedin.com/in/williamhgates/" --profile
101
+
102
+ # Scrape member profile by slug
103
+ python plugins/linkedin-scrape/cli.py "williamhgates" --profile
104
+ ```
105
+
106
+ ### 3. Company Intelligence Scraping
107
+ ```bash
108
+ # Scrape company profile
109
+ python plugins/linkedin-scrape/cli.py "https://www.linkedin.com/company/microsoft/" --company
110
+ ```
111
+
112
+ ### 4. Post Comments Extraction
113
+ ```bash
114
+ # Extract discussion comments from a LinkedIn post
115
+ python plugins/linkedin-scrape/cli.py "https://www.linkedin.com/posts/activity-123456789" --comments
116
+ ```
117
+
118
+ ---
119
+
120
+ ## ⚙️ CLI Flag Reference Table
121
+
122
+ | Flag | Shorthand | Type | Default | Description |
123
+ | :--- | :--- | :--- | :--- | :--- |
124
+ | `target` | - | `string` | `None` | LinkedIn profile URL, company slug, or post update link. |
125
+ | `--interactive` | `-i` | `flag` | `False` | Launch step-by-step interactive wizard. |
126
+ | `--stdout` | - | `flag` | `False` | Stream structured JSON directly to console. |
127
+ | `--profile` | - | `flag` | `False` | Scrape member profile (Experience, Headline, Bio). |
128
+ | `--company` | - | `flag` | `False` | Scrape company page intelligence. |
129
+ | `--comments` | - | `flag` | `False` | Extract discussion comments from post. |
130
+ | `--all` | `-a` | `flag` | `False` | Extract all available fields. |
131
+
132
+ ---
133
+
134
+ ## 🔒 Security & Defensive Engineering
135
+
136
+ 1. **Hard Ceiling Enforcement**: Strict 50 req/day limit per burner session.
137
+ 2. **Burner Cookie Storage**: Session tokens (`li_at`) are managed via `plugins/shared/session_manager.py` and stored in Git-ignored `.sessions.json`.
138
+ 3. **Randomized Human Pacing**: Enforces 4.0s to 8.0s delays between consecutive requests.
139
+
140
+ ---
141
+
142
+ ## 📄 License
143
+ MIT License. Part of the [SocialScrape](../../README.md) toolkit.
@@ -0,0 +1,47 @@
1
+ ---
2
+ name: linkedin-scrape
3
+ description: "Self-contained plugin and skill for scraping LinkedIn profiles, company directories, post articles, and comments with strict rate-limiting rails."
4
+ triggers:
5
+ - linkedin.com
6
+ - linkedin profile
7
+ - linkedin company
8
+ - linkedin post
9
+ - linkedin comments
10
+ ---
11
+
12
+ # LinkedIn Scrape Plugin & Skill
13
+
14
+ ## Overview
15
+ This plugin executes safe, structured extraction of LinkedIn data:
16
+ - **Member Profiles**: Headline, about summary, experience list, education, and skills.
17
+ - **Company Pages**: Industry, employee headcount, headquarters, and updates.
18
+ - **Posts & Articles**: Post body text, author, like count, and comment threads.
19
+ - **Safety Rails**: Built-in hard request limits per session to protect burner cookies.
20
+
21
+ All disk outputs are organized into structured directories inside `plugins/linkedin-scrape/Outputs/`:
22
+ - `Outputs/thumbnails/`
23
+ - `Outputs/comments/`
24
+ - `Outputs/text_posts/`
25
+
26
+ ---
27
+
28
+ ## ⚡ Execution Modes & Commands
29
+
30
+ ### 1. In-Memory / Zero-Disk Execution
31
+ ```bash
32
+ python plugins/linkedin-scrape/cli.py "<PROFILE_OR_COMPANY_URL>" --stdout
33
+ ```
34
+
35
+ ### 2. Extraction Saved to `Outputs/`
36
+ ```bash
37
+ # Extract full profile bundle
38
+ python plugins/linkedin-scrape/cli.py "<PROFILE_URL>" --all
39
+
40
+ # Extract post comments
41
+ python plugins/linkedin-scrape/cli.py "<POST_URL>" --comments
42
+ ```
43
+
44
+ ### 3. Interactive Wizard Mode
45
+ ```bash
46
+ python plugins/linkedin-scrape/cli.py -i
47
+ ```