Skip to content

Commit 1177de5

Browse files
committed
⚡ Add option to control no of comments to be parsed while scraping a linkedin post url
1 parent 4048361 commit 1177de5

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/linkedin_spider/core/scraper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def search_posts(
168168
keywords, max_results, scroll_pause, max_comments, date_posted
169169
)
170170

171-
def open_link(self, url: str) -> dict[str, Any] | None:
171+
def open_link(self, url: str, max_comments: int = 10) -> dict[str, Any] | None:
172172
"""
173173
Open a LinkedIn post URL and extract its content.
174174
@@ -178,7 +178,7 @@ def open_link(self, url: str) -> dict[str, Any] | None:
178178
Returns:
179179
Dictionary containing post data (same structure as search_posts), or None if failed
180180
"""
181-
return self.search_scraper.open_link(url)
181+
return self.search_scraper.open_link(url, max_comments=max_comments)
182182

183183
def scrape_company(self, company_url: str) -> dict[str, Any] | None:
184184
"""Scrape a LinkedIn company page."""

src/linkedin_spider/scrapers/search.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,7 @@ def _load_more_comments(self, container: WebElement, max_comments: int) -> None:
12271227
except Exception as e:
12281228
self.log_action("DEBUG", f"Error loading more comments: {e!s}")
12291229

1230-
def open_link(self, url: str) -> dict[str, Any] | None:
1230+
def open_link(self, url: str, max_comments: int = 10) -> dict[str, Any] | None:
12311231
"""
12321232
Open a LinkedIn post URL and extract its content.
12331233
@@ -1255,7 +1255,7 @@ def open_link(self, url: str) -> dict[str, Any] | None:
12551255
return None
12561256

12571257
# Extract data from the first post
1258-
post_data = self._extract_post_data(post_containers[0])
1258+
post_data = self._extract_post_data(post_containers[0], max_comments=max_comments)
12591259

12601260
# Set post_url if not already set
12611261
if post_data.get("post_url") == "N/A":

0 commit comments

Comments
 (0)