diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3b65983 --- /dev/null +++ b/.gitignore @@ -0,0 +1,144 @@ +.idea + +parameters.py + +# https://github.com/github/gitignore/blob/master/Python.gitignore + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ \ No newline at end of file diff --git a/README.md b/README.md index 41e442f..2a0f198 100644 --- a/README.md +++ b/README.md @@ -4,21 +4,18 @@ Python code to automatically expand your LinkedIn network based on your interest - - - - ## Prerequisites -Use the package manager [pip](https://pip.pypa.io/en/stable/) to install selenium. +Use the package manager [pip](https://pip.pypa.io/en/stable/) +to install the prerequisites. ```bash -pip install selenium -pip install webdriver-manager +pip install -r requirements.txt ``` ## How to use ? - - Open parameters.py file and provide your email id, password, and keywords for search criteria. + - Copy `parameters-sample.py` to `parameters.py` and edit `parameters.py` to + provide your email id, password, and keywords for search criteria. - Run `python linkedIn.py` diff --git a/linkedIn.py b/linkedIn.py index 1a54108..3c5328d 100644 --- a/linkedIn.py +++ b/linkedIn.py @@ -1,16 +1,19 @@ from selenium import webdriver -from webdriver_manager.chrome import ChromeDriverManager from selenium.webdriver.common.keys import Keys -import parameters, csv, os.path, time - +from webdriver_manager.chrome import ChromeDriverManager +import csv +import os.path +import parameters +import time -# Functions +# Functions def search_and_send_request(keywords, till_page, writer): for page in range(1, till_page + 1): print('\nINFO: Checking on page %s' % (page)) - query_url = 'https://www.linkedin.com/search/results/people/?keywords=' + keywords + '&origin=GLOBAL_SEARCH_HEADER&page=' + str(page) + query_url = 'https://www.linkedin.com/search/results/people/?keywords=' + keywords + '&origin=GLOBAL_SEARCH_HEADER&page=' + str( + page) driver.get(query_url) time.sleep(5) html = driver.find_element_by_tag_name('html') @@ -21,7 +24,7 @@ def search_and_send_request(keywords, till_page, writer): for connection in linkedin_urls: if connection.text == 'Connect': try: - coordinates = connection.location_once_scrolled_into_view # returns dict of X, Y coordinates + coordinates = connection.location_once_scrolled_into_view # returns dict of X, Y coordinates driver.execute_script("window.scrollTo(%s, %s);" % (coordinates['x'], coordinates['y'])) text = str(connection.get_attribute('aria-label')) print("INFO: %s" % (text)) @@ -38,7 +41,6 @@ def search_and_send_request(keywords, till_page, writer): time.sleep(5) - # Login driver = webdriver.Chrome(ChromeDriverManager().install()) driver.get('https://www.linkedin.com/login') @@ -46,31 +48,18 @@ def search_and_send_request(keywords, till_page, writer): driver.find_element_by_id('password').send_keys(parameters.linkedin_password) driver.find_element_by_xpath('//*[@type="submit"]').click() time.sleep(10) -#name = driver.find_elements_by_class_name('profile-rail-card__actor-link')[0].text.replace(' ', '') - - - +# name = driver.find_elements_by_class_name('profile-rail-card__actor-link')[0].text.replace(' ', '') # CSV file loging -#file_name = name + '_' + parameters.file_name.capitalize() +# file_name = name + '_' + parameters.file_name.capitalize() file_name = parameters.file_name -file_exists = os.path.isfile(file_name) +file_exists = os.path.isfile(file_name) writer = csv.writer(open(file_name, 'a')) if not file_exists: writer.writerow(['Connection Summary']) - - - - # Search search_and_send_request(keywords=parameters.keywords, till_page=parameters.till_page, writer=writer) - - - - # Close browser driver.quit() - - diff --git a/parameters-sample.py b/parameters-sample.py new file mode 100644 index 0000000..e4eddfb --- /dev/null +++ b/parameters-sample.py @@ -0,0 +1,5 @@ +file_name = 'connections.csv' +linkedin_username = 'XXXXX@gmail.com' +linkedin_password = 'XXXXXX' +keywords = 'DevOps,Linux,Python,AWS' +till_page = 10 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..dcbe6a6 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +selenium +webdriver-manager \ No newline at end of file