Spaces:
Sleeping
Sleeping
File size: 1,250 Bytes
54a8fe3 | 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 | from smolagents.tools import Tool
import requests
import os
class LinkedInProfileScraperTool(Tool):
name = "linkedin_profile_scraper"
description = "Fetches the LinkedIn profile information for a given url."
inputs = {'profile_url': {'type': 'string', 'description': 'The LinkedIn URL to fetch information for.'}}
output_type = "object"
def forward(self, profile_url: str) -> dict:
url = "https://linkedin-data-api.p.rapidapi.com/get-profile-data-by-url"
querystring = {"url": profile_url}
headers = {
"x-rapidapi-key": os.getenv("rapidapi"),
"x-rapidapi-host": "linkedin-data-api.p.rapidapi.com"
}
try:
response = requests.get(url, headers=headers, params=querystring)
response.raise_for_status()
profile_data = response.json()
keys_to_extract = ['firstName', 'lastName', 'summary', 'educations', 'position', 'skills', 'projects']
filtered_data = {key: profile_data[key] for key in keys_to_extract if key in profile_data}
return filtered_data
except requests.exceptions.RequestException as e:
return f"An error occurred while fetching the LinkedIn profile: {str(e)}"
|