Automate LinkedIn with Python and Selenium.
Project description
LinkedIn Python Bot
I built this project because I'm super lazy to check my LinkedIn account.
So by using this bot, I'll increase my profile views, interactions, followers, and connections.
And since I love sharing my stuff with others, I created this package.
So if you enjoy it, start it on GitHub.
- Features
- Installation
- Usage options
- 1. Posts Interactions
- 2. publishing
- 3. Network
- 4. Environment variables
- 5. Run it on a server
Features
- Interact with LinkedIn posts.
- Like
- Comment
- Auto post/image publishing
Installation
pip install automate-linkedin
or
pip install git+https://github.com/SelmiAbderrahim/automate-linkedin
Usage options
- CLI
You can use these features throught the command line interface (CLI), which is quite useful to run it on a server.
$ autoln OPTIONS
options:
- username: Your LinkedIn email address (required).
- password: Your LinkedIn email password (required).
- env: Get username & password as environment variables. (optional).
- headless: Hide the browser's window. (optional).
- API
You can use the same features on your own project (code) throught the API.
from automate_linkedin.interactions import Posts
class Interaction(Posts):
pass
For the LinkedIn authentication, I'm using the easy_selenium to create a Chrome driver and login to LinkedIn accounts.
2.1. Create driver
from easy_selenium.driver.chrome.driver import Driver
driver = Driver()
chrome = driver.create(headless=headless)
2.2. Login
from easy_selenium.authentication.login.linkedin import Login
login = Login(username, password)
authenticated = login.start(chrome)
1. Posts Interactions
CLI
Interact with the LinkedIn 'home page' or 'groups' posts.
Options
-
post-interaction: Interact with your LinkedIn posts. (required).
autoln --username plain_text_email --password plain_text_password --post-interaction
-
post-number-likes: Number of post likes [default: 5] (required).
autoln --username plain_text_email --password plain_text_password --post-interaction --post-number-likes 10
-
env: Get username & password as environment variables. (optional).
autoln --env --username LINKEDIN_EMAIL_ADDRESS --password LINKEDIN_PASSWORD --post-interaction
-
headless: Hide the browser's window. (optional).
autoln --env --headless --username LINKEDIN_EMAIL_ADDRESS --password LINKEDIN_PASSWORD --post-interaction
-
comment-number-likes: The number of likes of comments. (optional).
-
like-post-comments: Like comments of each posts. (optional).
autoln --env --headless --username LINKEDIN_EMAIL_ADDRESS --password LINKEDIN_PASSWORD --post-interaction --like-post-comments --comment-number-likes 2
-
auto-comment: Comment with positive examples. (optional).
autoln --env --headless --username LINKEDIN_EMAIL_ADDRESS --password LINKEDIN_PASSWORD --post-interaction --auto-comment
💡 Example: If I want to run a headless browser to like 20 posts and comment on any of these posts if possible.
autoln --env --headless --username LINKEDIN_EMAIL_ADDRESS --password LINKEDIN_PASSWORD --post-interaction --auto-comment --post-number-likes 25
API
After creating a Chrome driver and making sure you're authenticated, as shown above, you can use this function to interact with posts on your LinkedIn pages and groups.
from interactions import Posts
posts = Posts()
posts.start(chrome)
Attributes:
>> print(Posts.__doc__)
Interact with the LinkedIn posts.
Params:
number_of_posts_to_like (int): Number of posts to like (default = 5).
number_of_post_comments_to_like (int): Number of comments to like for each post (default = 2).
like_post_comments (bool): Start liking comments (default = False).
auto_comment (bool): Post a positive comment for random posts (default = False).
url (str): The page's url (default = 'https://www.linkedin.com/feed')
short_sleep_range (tuple[float, float]): time.sleep(short range) (default = (0.5, 0.9))
long_sleep_range (tuple[float, float]): time.sleep(long range) (default = (1.5, 4.9))
Returns:
None
2. publishing
CLI
This will allow you to publish a post with an image or text on your LinkedIn profile.
options:
- --publish: Enable the publishing option (required).
- --text: The text content of the post (optional).
- --image-path: The absolute path of the image (optional).
💡 Example: If I want to publish a post with my image and greeting message.
autoln --env --headless --username LINKEDIN_EMAIL_ADDRESS --password LINKEDIN_PASSWORD --publish --text "Hi people!" --image-path C:\\images\me.png
API
Post text only
from automate_linkedin.publish import Publish
p = Publish()
p.post(chrome, content="greeting!")
Post text and image
from automate_linkedin.publish import Publish
p = Publish()
p.image(chrome, r"C:\Users\selmi\Pictures\BloggersHood1.png", content="zfzazafazf")
3. Network
Manage your network.
3.1. Follow people
You can follow up to 16 people each time.
CLI
autoln --env --headless --username LINKEDIN_EMAIL_ADDRESS --password LINKEDIN_PASSWORD --follow-network
API
from automate_linkedin.networkk import Follow
follow = Follow()
follow.start(driver)
3.2. Connect with people
You can send invites up to 16 people each time.
CLI
autoln --env --headless --username LINKEDIN_EMAIL_ADDRESS --password LINKEDIN_PASSWORD --connect-network
API
from automate_linkedin.networkk import Connect
connect = Connect()
connect.start(driver)
4. Environment variables
There many reasons for using environment variables in your projects, including:
- Easy configuration
- Better security
- Fewer production mistakes
So in your working directory, create a new file .env
and place the secrets you'll use with this package.
Exmaple
LINKEDIN_EMAIL_ADDRESS=example@email.com
LINKEDIN_PASSWORD=password
Then you gonna use it throught the cli:
autoln --env --username LINKEDIN_EMAIL_ADDRESS --password LINKEDIN_PASSWORD
5. Run it on a server
I have tested the below code on my Ubuntu server, if something went wrong, please open a new issue.
- The first thing you have to do is installing Chrome
sudo apt-get update
sudo apt-get install google-chrome-stable
google-chrome --version
- Login to your server
ssh user@ip
- Create a virtualenv
Linux/Mac
python -m pip install virtualenv
python -m virtualenv env
source env/bin/activate
Windows
py -m pip install virtualenv
py -m virtualenv env
env\Scripts\activate
- Install
automate-linkedin
pip install automate-linkedin
- Create a new
bash
file with the content below
Let's assume this is my working directory
selmi@7BNVUM:/selmi$ pwd
/home/selmi/automate-linkedin
Then we create a new file like.sh
in that working directory.
#!/usr/bin/env bash
SHELL=/bin/bash
DISPLAY=:0
PATH=$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
cd /home/selmi/automate-linkedin
autoln --env --headless --username LINKEDIN_EMAIL_ADDRESS --password LINKEDIN_PASSWORD --post-interaction --like-post-comments --comment-number-likes 2 --post-number-likes 10 --auto-comment
Then for the permissions:
sudo chmod +x /home/selmi/automate-linkedin/likes.sh
-
Environment variables see this
-
Crontab
and finally, we automate the process using crontab.
crontab -e
To run that bash file every 5 hours, add this line:
0 */5 * * * ./home/selmi/automate-linkedin/likes.sh
Then save it.
That's it.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file Automate LinkedIn-0.1.2.tar.gz
.
File metadata
- Download URL: Automate LinkedIn-0.1.2.tar.gz
- Upload date:
- Size: 12.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08ed940312b98ec5d583770759e8bb59824e391a88ae765e147c5782b0d02128 |
|
MD5 | b587caf0597822fb1f8da0d500284406 |
|
BLAKE2b-256 | a9d1d63b46e3c574291067afb662d0406d8e2acbbb665b5564b9834cb4e46e8c |
File details
Details for the file Automate_LinkedIn-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: Automate_LinkedIn-0.1.2-py3-none-any.whl
- Upload date:
- Size: 14.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e4e9aa8a1931783d7561df95a14dd171163c39bd0f3efc80220d27be8f38174 |
|
MD5 | 72ff075437d3333f0f0cbb664b60c6e4 |
|
BLAKE2b-256 | 908ebd23a7bbb97dfd7c1ec333fcf4694264cd3cfc497123098a20281eec5062 |