Skip to content

Instantly share code, notes, and snippets.

@juddlyon
Created March 20, 2020 17:37
Show Gist options
  • Save juddlyon/ac11012563c80f40cd21bebc22df842e to your computer and use it in GitHub Desktop.
Save juddlyon/ac11012563c80f40cd21bebc22df842e to your computer and use it in GitHub Desktop.
Create CSV list of blogs from Bloglovin
#!/usr/bin/python3
import requests
import csv
api_base_url = 'https://www.bloglovin.com/api'
url = api_base_url + '/v2/search?q=mensfashion&t=true'
# cat URI format: /v2/blogs/21?page=1&country=us
# search URI format: /v2/search?q=mensfashion&t=true
f = open('bloglovin_mens_fashion.csv', 'w')
index = 0
with f:
fnames = ['NAME', 'URL', 'DESC']
writer = csv.DictWriter(f, fieldnames = fnames)
writer.writeheader()
while url:
response = requests.get(url)
data = response.json()
blogs = data['meta']['resolved']['blog']
for key in blogs:
writer.writerow({
'NAME': blogs[key]['name'],
'URL': blogs[key]['url'],
'DESC': blogs[key]['desc']
})
if 'nextUrl' in data['meta']:
url = api_base_url + data['meta']['nextUrl']
index += 1
print('✓ processed page #' + str(index))
else:
print('✗ No more records, ended on page #' + str(index))
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment