Skip to content

Instantly share code, notes, and snippets.

@Tafkas
Created November 13, 2013 00:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tafkas/7441581 to your computer and use it in GitHub Desktop.
Save Tafkas/7441581 to your computer and use it in GitHub Desktop.
Downloads all participant information from http://www.bmw-berlin-marathon.com/en/results-and-list-of-participants/participant-list.html and stores it in a csv file
#!/usr/bin/env python
# encoding: utf-8
"""
berlin_marathon_participants_2014.py
Created by Christian Stade-Schuldt on 2013-11-12.
"""
import urllib
import json
import time
import csv
def main():
"""Downloads all participant information from
http://www.bmw-berlin-marathon.com/en/results-and-list-of-participants/participant-list.html
and stores it in a csv file"""
base_url = "http://www.bmw-berlin-marathon.com/files/addons/scc_events_data/ajax.teilnehmer.php?ident=MAH,MAL,MAR,MAW,MAI&_search=false&nd=1384301124189&rows=100&page="
all_runner = []
for i in range(1, 169):
url = base_url + "%d&sidx=teilnehmer_name&sord=asc" % i
print url
response = urllib.urlopen(url)
data = json.loads(response.read())
for row in data["rows"]:
runner_id = row["cell"][0]
last_name = row["cell"][2]
first_name = row["cell"][3]
country = row["cell"][4]
birth_date = row["cell"][5]
team = row["cell"][6]
city = row["cell"][7]
runner = (runner_id, last_name, first_name, country, birth_date, team, city)
all_runner.append(runner)
time.sleep(1)
print len(all_runner)
with open("output.csv", "wb") as f:
writer = csv.writer(f)
writer.writerow(["id", "last_name", "first_name", "country", "birth_date", "team", "city"])
for runner in all_runner:
writer.writerow([k.encode('utf-8') for k in runner])
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment