fix: LinkedIn MCP 参数适配 — 用 company_name/linkedin_username 替代 url
linkedin-scraper-mcp 的 API 参数是 company_name 和 linkedin_username, 不是 url。从 URL 中提取 slug 传给 MCP。 timeout 增加到 60 秒(浏览器自动化需要时间)。 search 去掉不支持的 limit 参数。
This commit is contained in:
@@ -89,13 +89,19 @@ class LinkedInChannel(Channel):
|
|||||||
|
|
||||||
async def _read_profile_mcp(self, url: str) -> ReadResult:
|
async def _read_profile_mcp(self, url: str) -> ReadResult:
|
||||||
"""Read a LinkedIn profile via MCP."""
|
"""Read a LinkedIn profile via MCP."""
|
||||||
safe_url = url.replace('"', '\\"')
|
import re
|
||||||
|
# Extract username from URL: /in/username/
|
||||||
|
match = re.search(r"/in/([^/]+)", url)
|
||||||
|
if not match:
|
||||||
|
return await self._read_jina(url)
|
||||||
|
username = match.group(1)
|
||||||
|
safe_username = username.replace('"', '\\"')
|
||||||
out = _mcporter_call(
|
out = _mcporter_call(
|
||||||
f'linkedin.get_person_profile(url: "{safe_url}")',
|
f'linkedin.get_person_profile(linkedin_username: "{safe_username}")',
|
||||||
timeout=30,
|
timeout=60,
|
||||||
)
|
)
|
||||||
return ReadResult(
|
return ReadResult(
|
||||||
title=self._extract_title(out) or "LinkedIn Profile",
|
title=self._extract_title(out) or f"LinkedIn Profile - {username}",
|
||||||
content=out.strip(),
|
content=out.strip(),
|
||||||
url=url,
|
url=url,
|
||||||
platform="linkedin",
|
platform="linkedin",
|
||||||
@@ -103,10 +109,16 @@ class LinkedInChannel(Channel):
|
|||||||
|
|
||||||
async def _read_company_mcp(self, url: str) -> ReadResult:
|
async def _read_company_mcp(self, url: str) -> ReadResult:
|
||||||
"""Read a LinkedIn company page via MCP."""
|
"""Read a LinkedIn company page via MCP."""
|
||||||
safe_url = url.replace('"', '\\"')
|
import re
|
||||||
|
# Extract company name from URL: /company/name/
|
||||||
|
match = re.search(r"/company/([^/]+)", url)
|
||||||
|
if not match:
|
||||||
|
return await self._read_jina(url)
|
||||||
|
company = match.group(1)
|
||||||
|
safe_company = company.replace('"', '\\"')
|
||||||
out = _mcporter_call(
|
out = _mcporter_call(
|
||||||
f'linkedin.get_company_profile(url: "{safe_url}")',
|
f'linkedin.get_company_profile(company_name: "{safe_company}")',
|
||||||
timeout=30,
|
timeout=60,
|
||||||
)
|
)
|
||||||
return ReadResult(
|
return ReadResult(
|
||||||
title=self._extract_title(out) or "LinkedIn Company",
|
title=self._extract_title(out) or "LinkedIn Company",
|
||||||
@@ -202,20 +214,20 @@ class LinkedInChannel(Channel):
|
|||||||
# Try job search first (most common use case)
|
# Try job search first (most common use case)
|
||||||
try:
|
try:
|
||||||
out = _mcporter_call(
|
out = _mcporter_call(
|
||||||
f'linkedin.search_jobs(keywords: "{safe_q}", limit: {limit})',
|
f'linkedin.search_jobs(keywords: "{safe_q}")',
|
||||||
timeout=30,
|
timeout=60,
|
||||||
)
|
)
|
||||||
results = self._parse_search_results(out, "job")
|
results = self._parse_search_results(out, "job")
|
||||||
if results:
|
if results:
|
||||||
return results
|
return results[:limit]
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Try people search
|
# Try people search
|
||||||
try:
|
try:
|
||||||
out = _mcporter_call(
|
out = _mcporter_call(
|
||||||
f'linkedin.search_people(keywords: "{safe_q}", limit: {limit})',
|
f'linkedin.search_people(keywords: "{safe_q}")',
|
||||||
timeout=30,
|
timeout=60,
|
||||||
)
|
)
|
||||||
results = self._parse_search_results(out, "people")
|
results = self._parse_search_results(out, "people")
|
||||||
if results:
|
if results:
|
||||||
|
|||||||
Reference in New Issue
Block a user