title: How to get table using rvest()
body: <p>I want to grab some data from Pro Football Reference website using the <code>rvest</code> package. First, let's grab results for all games played in 2015 from this url <code>http://www.pro-football-reference.com/years/2015/games.htm</code></p>
  
  <pre><code>library("rvest")
  library("dplyr")
  
  #grab table info
  url &lt;- "http://www.pro-football-reference.com/years/2015/games.htm"
  urlHtml &lt;- url %&gt;% read_html() 
  dat &lt;- urlHtml %&gt;% html_table(header=TRUE) %&gt;% .[[1]] %&gt;% as_data_frame()
  </code></pre>
  
  <p>Is that how you would have done it? :) </p>
  
  <p><code>dat</code> could be cleaned up a bit. Two of the variables seem to have blanks for names. Plus the header row is repeated between each week.</p>
  
  <pre><code>colnames(dat) &lt;- c("week", "day", "date", "winner", "at", "loser", 
                     "box", "ptsW", "ptsL", "ydsW", "toW", "ydsL", "toL")
  
  dat2 &lt;- dat %&gt;% filter(!(box == ""))
  head(dat2)
  </code></pre>
  
  <p>Looks good!</p>
  
  <p>Now let's look at an individual game. At the webpage above, click on "Boxscore" in the very first row of the table: The Sept 10th game played between New England and Pittsburgh. That takes us here: <code>http://www.pro-football-reference.com/boxscores/201509100nwe.htm</code>.</p>
  
  <p>I want to grab the individual snap counts for each player (about half way down the page). Pretty sure these will be our first two lines of code:</p>
  
  <pre><code>gameUrl &lt;- "http://www.pro-football-reference.com/boxscores/201509100nwe.htm"
  gameHtml &lt;- gameUrl %&gt;% read_html()
  </code></pre>
  
  <p>But now I can't figure out how to grab the specific table I want. I use the Selector Gadget to highlight the table of Patriots snap counts. I do this by clicking on the table in several places, then 'unclicking' the other tables that were highlighted. I end up with a path of:</p>
  
  <p><code>#home_snap_counts .right , #home_snap_counts .left, #home_snap_counts .left, #home_snap_counts .tooltip, #home_snap_counts .left</code> </p>
  
  <p>Each of these attempts returns <code>{xml_nodeset (0)}</code></p>
  
  <pre><code>gameHtml %&gt;% html_nodes("#home_snap_counts .right , #home_snap_counts .left, #home_snap_counts .left, #home_snap_counts .tooltip, #home_snap_counts .left")
  gameHtml %&gt;% html_nodes("#home_snap_counts .right , #home_snap_counts .left")
  gameHtml %&gt;% html_nodes("#home_snap_counts .right")
  gameHtml %&gt;% html_nodes("#home_snap_counts")
  </code></pre>
  
  <p>Maybe let's try using <code>xpath</code>. All of these attempts also return <code>{xml_nodeset (0)}</code></p>
  
  <pre><code>gameHtml %&gt;% html_nodes(xpath = '//*[(@id = "home_snap_counts")]//*[contains(concat( " ", @class, " " ), concat( " ", "right", " " ))] | //*[(@id = "home_snap_counts")]//*[contains(concat( " ", @class, " " ), concat( " ", "left", " " ))]//*[(@id = "home_snap_counts")]//*[contains(concat( " ", @class, " " ), concat( " ", "left", " " ))]//*[(@id = "home_snap_counts")]//*[contains(concat( " ", @class, " " ), concat( " ", "tooltip", " " ))]//*[(@id = "home_snap_counts")]//*[contains(concat( " ", @class, " " ), concat( " ", "left", " " ))]')
  gameHtml %&gt;% html_nodes(xpath = '//*[(@id = "home_snap_counts")]//*[contains(concat( " ", @class, " " ))]')
  gameHtml %&gt;% html_nodes(xpath = '//*[(@id = "home_snap_counts")]')
  </code></pre>
  
  <p>How can I grab that table? I'll also point out, when I do "View Page Source" in Google Chrome, the tables I want almost seem to be commented out? That is, they're typed in green, instead of the usual red/black/blue color scheme. That is not the case for the table of game results we pulled first. "View Page Source" for that table is the usual red/black/blue color scheme. Is the greenness indicative of what's preventing me from being able to grab this snap count table?</p>
  
  <p>Thanks!</p>