Skip to content

Instantly share code, notes, and snippets.

@lwiecek
Created February 7, 2014 00:29
Show Gist options
  • Save lwiecek/8855318 to your computer and use it in GitHub Desktop.
Save lwiecek/8855318 to your computer and use it in GitHub Desktop.
Livescore results
import requests
from lxml.html.soupparser import fromstring
import csv
r = requests.get('http://livescore.com')
root = fromstring(r.text)
home_teams = root.xpath('//td[@class="fh"]/text()')
away_teams = root.xpath('//td[@class="fa"]/text()')
scores = root.xpath('//td[@class="fs"]/a/text()')
with open('scores.csv', 'wb') as csvfile:
writer = csv.writer(csvfile)
for home, away, score in zip(home_teams, away_teams, scores):
try:
home_score, away_score = score.split('-')
row = [home.strip(), away.strip(), home_score.strip(), away_score.strip()]
print 'writing', row
writer.writerow(row)
except: # TODO failing due to some unicode stuff probably getting only ascii chars would fix that
pass # ignore for now
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment