Skip to content

Instantly share code, notes, and snippets.

Created July 22, 2020 04:32
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
import datetime
import requests
import csv
import json
import re
URL = ""
API_KEY = ''
request_url = "{}&siteUrl={}".format(API_KEY, URL)
request = requests.get(request_url)
if request.status_code == 200:
query_data = json.loads(request.text)
with open("bing_query_stats_{}.csv".format(, mode='w') as new_file:
write_row = csv.writer(new_file, delimiter=',', quotechar='"')
write_row.writerow(['AvgClickPosition', 'AvgImpressionPosition', 'Clicks', 'Impressions', 'Query', 'Created', 'Date'])
for key in query_data["d"]:
# Get date
match ='/Date\\((.*)\\)/', key["Date"])
write_row.writerow([key["AvgClickPosition"] / 10,
key["AvgImpressionPosition"] / 10,
datetime.datetime.fromtimestamp(int( // 1000)])
Copy link

Thanks for building out the code! Is there a way to ping a Bing WMT endpoint for keyword-level stats, especially for keyword-level Impressions? And also Impressions that go back 6 months?


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment