An AI-powered LinkedIn automation tool that helps you connect with people or send messages to your connections. The script uses OpenAI's Computer-use API to automate browser interactions in a human-like manner.
- Single or Multiple Targets: Connect with a single person or process multiple targets from a JSON file
- Smart Connection Logic: Automatically detects if you're already connected and sends a message instead
- Fallback Search Strategy: If a profile isn't found with name+company, tries with just the name
- Customizable Messages: Define connection requests and messages for already connected profiles
- Robust Error Handling: Detailed logging and error reporting
- Python 3.9+
- OpenAI API key with access to computer-use-preview model
- LinkedIn account credentials
- Required Python packages (see Installation)
-
Clone this repository:
git clone https://github.com/DeepMyst/Linkedin-Connector-Agent cd linkedin-connector-agent -
Install required dependencies:
pip install openai python-dotenv playwright
-
Install Playwright browsers:
python -m playwright install
-
Create a
.envfile in the project directory with your credentials:OPENAI_API_KEY=your_openai_api_key LINKEDIN_EMAIL=your_linkedin_email LINKEDIN_PASSWORD=your_linkedin_password
You can process a single target by setting environment variables:
export LINKEDIN_TARGET_NAME="Jane Doe"
export LINKEDIN_TARGET_COMPANY="Tech Company"
export LINKEDIN_TARGET_MESSAGE="Great meeting you yesterday. Let's connect!"
python linkedin_script.pyOr by directly modifying the target information in the script.
Create a JSON file (e.g., targets.json) with your targets:
[
{
"name": "Jane Doe",
"company": "Tech Company",
"message": "It was great meeting you at the conference. Let's connect!"
},
{
"name": "John Smith",
"company": "Startup Inc",
"message": "I enjoyed our conversation about AI ethics. Would love to continue the discussion."
}
]Then run the script with the targets file:
python linkedin_script.py --targets targets.jsonAlternatively, you can set the targets file as an environment variable:
export LINKEDIN_TARGETS_FILE=targets.json
python linkedin_script.pyTo run without displaying the browser window (useful for automated runs):
python linkedin_script.py --headless
# Or for multiple targets
python linkedin_script.py --targets targets.json --headlessYou can also enable headless mode via environment variable:
export LINKEDIN_HEADLESS=true
python linkedin_script.pyThe script follows these steps for each target:
- Logs into LinkedIn using your credentials
- Searches for the target person by name and company
- If not found, tries searching by just the name
- Opens the profile page
- Determines if you're already connected:
- If not connected: Sends a connection request with your custom message
- If already connected: Sends a direct message
You can customize the default messages by modifying the script:
- Connection request message (for new connections)
- Already connected message (for existing connections)
The script uses Python's logging module to log its activities. You can adjust the logging level in the script to get more or less detailed logs.
- Your LinkedIn credentials and OpenAI API key are stored locally in the
.envfile - The script runs locally on your machine and doesn't send your credentials to any third-party servers
- However, your screen is captured and sent to OpenAI's API during the automation process
- Login Issues: Make sure your LinkedIn credentials are correct and your account doesn't have 2FA enabled
- Search Problems: If the script can't find profiles, try using more specific names or companies
- Connection/Message Failures: LinkedIn may limit the number of connections you can send; consider running the script with fewer targets
- LinkedIn may restrict accounts that make too many connection requests in a short period
- The script depends on LinkedIn's current UI; future updates to LinkedIn may require script updates
- OpenAI's computer-use API may change or have rate limits
This tool is provided for educational purposes only. Use it responsibly and in accordance with LinkedIn's terms of service. Excessive automation may lead to account restrictions.