Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make repository more standard: add requirements.txt and .gitignore #2

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 144 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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/
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`


Expand Down
35 changes: 12 additions & 23 deletions linkedIn.py
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -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))
Expand All @@ -38,39 +41,25 @@ 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')
driver.find_element_by_id('username').send_keys(parameters.linkedin_username)
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()


5 changes: 5 additions & 0 deletions parameters-sample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
file_name = 'connections.csv'
linkedin_username = '[email protected]'
linkedin_password = 'XXXXXX'
keywords = 'DevOps,Linux,Python,AWS'
till_page = 10
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
selenium
webdriver-manager