I am using Windows 7 with Pycharm and Notebook++ With the Python code below I have managed to extract the data required from the following HTML
<div class="resultsBlock">
<ul class="header">
<li class="first essential fin">Fin</li>
<li class="essential greyhound">Greyhound</li>
<li class="trap">Trap</li>
<li class="sp">SP</li>
<li class="timeSec">Time/Sec.</li>
<li class="timeDistance">Time/Distance</li>
</ul>
The code extracts finishing position, name trap, sp, timeSec and timeDistance, and places the information into a csv file. Just above this code in the Source is the following HTML
<div class="resultsBlockHeader clearfix mediumRoundedCorners">
<div class="track">Belle Vue | </div>
<div class="date">23/08/15</div>
<div class="datetime">13:51 | </div>
<div class="grade">A7 | </div>
<div class="distance">470m | </div>
<div class="prizes">1st £56, Others £20 (BGRF added £30)</div>
So effectively from my Python code I replace this:
one = bsObj.findAll("li", {"class": "first essential fin"})
with this
track = bsObj.findAll("div", {"class": "track"})
However when I do this Python ignores it and doesn't even furnish me with any messages telling me why it has ignored this code. Below is the code in full and at the beginning I have just placed one line of code that attempts to extract the div class line.Any suggestion appreciated.
import csv
from urllib import urlopen
from bs4 import BeautifulSoup
html = urlopen("http://www.gbgb.org.uk/resultsRace.aspx?id=1793467" )
bsObj = BeautifulSoup(html)
track = bsObj.findAll("div", {"class": "track"})#the line that wont work
one = bsObj.findAll("li", {"class": "first essential fin"})
two = bsObj.findAll("li", {"class": "essential greyhound"})
four = bsObj.findAll("li", {"class": "timeDistance"})
five = bsObj.findAll("li", {"class": "trap"})
six = bsObj.findAll("li", {"class": "sp"})
seven = bsObj.findAll("li", {"class": "timeSec"})
eight = bsObj.findAll("li", {"class": "essential trainer"})
nine = bsObj.findAll("li", {"class": "first essential comment"})
ten = bsObj.findAll("div", {"class": "track"})
firstessentialfin = [ a.getText().strip() for a in one ]
essentialgreyhound = [ b.getText().strip() for b in two]
timeDistance = [ c.getText().strip() for c in four]
trap = [ d.getText().strip() for d in five ]
sp = [ e.getText().strip() for e in six ]
timeSec = [ f.getText().strip() for f in seven]
essentialtrainer = [ g.getText().strip() for g in eight]
firstessentialcomment = [ h.getText().strip() for in nine]
track = [ i.getText().strip() for i in ten]
with open('lugs.csv', 'wb') as csvfile:
writer = csv.writer(csvfile, delimiter=",")
for f in zip(firstessentialfin, essentialgreyhound, trap, timeSec, timeDistance,sp,track):
writer.writerow(f)