Spaces:
Sleeping
Sleeping
| 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)}" | |