A simple CrewAI tool giving agents access to search for accounts on LinkedIn and scrape account data for those found accounts. It uses LinkedIn's somewhat standardized structure to search for people on the platform and extract common profile fields like name, title, company, location, etc. Additionally, it looks for their experience, activity, and education. It gives CrewAI agents the ability to search for this information and perform name lookups.
-
Clone the repository:
git clone https://github.com/your-username/Linkedin_Agent_Tool.git
-
Navigate to the project directory:
cd Linkedin_Agent_Tool
-
Create a virtual environment (optional but recommended):
python -m venv linkedin_agent-env
-
Activate the virtual environment:
- For Windows:
linkedin_agent-env\Scripts\activate
- For macOS and Linux:
source linkedin_agent-env/bin/activate
- For Windows:
-
Install the required dependencies:
pip install -r requirements.txt
To use the Linkedin Agent Tool, follow these steps:
-
Set up your LinkedIn login credentials as environment variables:
LINKEDIN_USERNAME
: Your LinkedIn username or email.LINKEDIN_PASSWORD
: Your LinkedIn password.
-
Create an instance of the
LinkedinAccountSearch
andLinkedinAccountDetailsTool
classes, passing the Selenium WebDriver as a parameter:# activate web driver driver = webdriver.Chrome() # automatic login and cookie handling login_linkedin( username=os.environ["LINKEDIN_USERNAME"], password=os.environ["LINKEDIN_PASSWORD"], driver=driver, bypassCookie=False) # setup the agent tools using the authenticated driver account_search = LinkedinAccountSearch(selenium_webdriver=driver) account_details_scraper = LinkedinAccountDetailsTool(selenium_webdriver=driver)
-
Create an instance of the
Agent
class, specifying the role, goal, backstory, and tools:LinkedinSearch_agent = Agent( role="LinkedIn researcher", goal="Identify LinkedIn profiles based on search criteria and extract relevant information", backstory="...", tools=[account_search, account_details_scraper], verbose=True, allow_delegation=False )
-
Define tasks for the agent using the
Task
class, specifying the description, expected output, output file, and the agent:find_all_john_smiths = Task( description="Search for 'John Smith' on LinkedIn and get top 5 profiles", expected_output="A json containing top 5 LinkedIn profiles for 'John Smith'", output_file="./tools/test_output/john_smiths_list.json", agent=LinkedinSearch_agent )
-
Create an instance of the
Crew
class, specifying the agents and tasks:test_crew = Crew( agents=[LinkedinSearch_agent], tasks=[find_all_john_smiths, search_for_daniel_task], verbose=2 )
-
Kick off the crew to execute the tasks:
test_crew.kickoff()
For a complete example, refer to the @Linkedin_Agent_Tool/search_crew_test.py
file.
The tool handles logging in using your provided login credentials and saves the cookie to avoid frequent re-authentication. It does require some level of monitoring as LinkedIn's anti-bot systems are quite robust and may block access if too many requests are made too quickly. When that happens, you will see a CAPTCHA challenge. If you fill it out, it will fix the problem, and the agent will continue.