Skip to content

Instantly share code, notes, and snippets.

@saasindustries
Created October 27, 2020 18:41
Show Gist options
  • Save saasindustries/808e780e30fc46207c96b1f5e039957a to your computer and use it in GitHub Desktop.
Save saasindustries/808e780e30fc46207c96b1f5e039957a to your computer and use it in GitHub Desktop.
import requests
import csv
APIKEY = 'YOUR API KEY HERE'
NUM = 5
def check_urls(urls):
headers = {
'apikey': APIKEY
}
params = {
'q': ' OR '.join(['site:' + x for x in urls]),
'num': 100
}
r = requests.get('https://app.zenserp.com/api/v2/search', params=params, headers=headers)
results = list()
if r.ok:
data = r.json()
if 'organic' in data.keys():
for url in urls:
found = False
for organic_result in data['organic']:
if url in organic_result['url']:
found = True
results.append([url, 'indexed'])
break
if not found:
results.append([url, 'not-indexed'])
return results
rows = list()
with open('urls.csv', 'r') as inFile:
reader = csv.reader(inFile)
to_check = list()
for row in reader:
if len(to_check) == NUM:
rows.append(check_urls(to_check))
to_check = list()
to_check.append(row[0])
if len(to_check) > 0:
rows.append(check_urls(to_check))
with open('results.csv', 'w', newline='', encoding='utf-8') as outFile:
writer = csv.writer(outFile)
for row in rows:
for r in row:
writer.writerow(r)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment