/ Published in: Python
Needs the BeautifulSoup module.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
import os import urllib2 import sys from BeautifulSoup import BeautifulSoup bbcurl = "http://news.bbc.co.uk/sport2/hi/football/eng_prem/fixtures/default.stm" doc = urllib2.urlopen(bbcurl).read() soup = BeautifulSoup(doc) mvbs = soup.findAll('div', { 'class' : 'mvb' }) for mvb in mvbs: if mvb.b: date = mvb.b.contents else: mvb = mvb.findNext('span') home = mvb.a.contents mvb = mvb.findNext('span') away = str(mvb.a.contents) print "DATE %s %s vs %s" % (date, home, away)