Search code examples
javascriptweb-scrapingphantomjscasperjs

Scrape a table with casperjs


I am trying to download some historical basketball data from basketball-reference website (for example, http://www.basketball-reference.com/boxscores/201601180CLE.html) using phantomjs/casperjs. For my purposes i need to scrape last row from the first table:

    <tr class="bold_text stat_total" data-row="14">
   <td align="left">Team Totals</td>
   <td align="right">240</td>
   <td align="right">.681</td>
   <td align="right">.653</td>
   <td align="right">.471</td>
   <td align="right">.318</td>
   <td align="right">17.6</td>
   <td align="right">79.5</td>
   <td align="right">50.7</td>
   <td align="right">71.7</td>
   <td align="right">7.4</td>
   <td align="right">3.4</td>
   <td align="right">7.6</td>
   <td align="right">100.0</td>
   <td align="right">139.2</td>
   <td align="right">103.3</td>
   </tr>

How could it be done with casperjs? My problem with this is that the row doesn't have id. Maybe would be easier to click on "PRE"-button:

<span tip="Convert the table below to pre-formatted text" class="tooltip" onclick="table2pre('GSW_basic'); try { ga('send','event','Tool','Action','PRE'); } catch (err) {}">PRE</span> 

Should the button be clicked, a simple version of table is depicted. Will it be easier way?


Solution

  • The last row of the table doesn't have its id, but it's the only row inside table footer <tfoot> element, so the jQuery (it's used at the target site) selector would be

    $("#GSW_basic tfoot tr")

    Or you could of course find it by its class:

    $("#GSW_basic .stat_total")