Skip to content

Instantly share code, notes, and snippets.

@thilohuellmann
Created July 17, 2018 14:42
Show Gist options
  • Save thilohuellmann/c25419c95dfb4383b106f144ba7c775d to your computer and use it in GitHub Desktop.
Save thilohuellmann/c25419c95dfb4383b106f144ba7c775d to your computer and use it in GitHub Desktop.
import http.client, urllib.request, urllib.parse, urllib.error, base64
import json
import csv
names = ['YOUR LIST OF NAMES']
companies = ['YOUR LIST OF COMPANIES FOR EACH NAME']
YOUR_API_KEY = 'YOUR_API_KEY'
linkedin = []
for name, company in zip(names, companies): # zip to loop over names and companies simultaneously
query = name + company
try:
headers = {'Ocp-Apim-Subscription-Key': YOUR_API_KEY }
params = urllib.parse.urlencode({'q': query,'count': '2','mkt': 'de-DE'}) # returns top 2 (German) results
conn = http.client.HTTPSConnection('api.cognitive.microsoft.com')
conn.request("GET", "/bing/v5.0/search?%s" % params, "{body}", headers)
response = conn.getresponse()
data = response.read().decode('utf-8')
json_file = json.loads(data)
conn.close()
for result in json_file['webPages']['value']:
title = result['name']
if name.lower() in title.lower(): # checks if the name appears in the title
if 'linkedin.com/in/' in result['displayUrl']: # checks if the search result URL is a LI profile
linkedin.append([name, company, result['displayUrl']])
break
except Exception as e:
print(e)
continue
# Writing the results to a CSV file
with open('linkedin.csv', 'w', newline='', encoding='utf-8') as f:
writer = csv.writer(f)
for row in linkedin:
writer.writerow(row)
print('Number of LinkedIn profiles found:')
print(len(linkedin))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment