title: use rvest and css selector to extract table from scraped search results
body: <p>Just learned about <code>rvest</code> on Hadley's great <a href="https://github.com/rstudio/webinars/tree/master/11-Getting-Data-into-R" rel="nofollow noreferrer">webinar</a> and trying it out for the first time.</p>
  
  <p>I want to scrape (and then plot) the baseball standings table returned from a Google search result.</p>
  
  <p>My problem is that I cannot get in <code>rvest</code> the table I see in my browser plug-in. </p>
  
  <p><img src="https://i.stack.imgur.com/dLHDJ.png" alt="enter image description here"></p>
  
  <pre><code>library(rvest)
  library(magrittr) # for %&gt;% operator
  
  ( g_search &lt;-html_session(url = "http://www.google.com/?q=mlb+standings", 
                            add_headers("user-agent" = "Mozilla/5.0")) )
  # &lt;session&gt; http://www.google.com/?q=mlb+standings
  #   Status: 200
  #   Type:   text/html; charset=UTF-8
  #   Size:   52500
  </code></pre>
  
  <p>This search should return a page with a table buried under many layers but uniquely identified by <code>&lt;div class="tb_strip"&gt;</code>.  A quick stop at the <a href="http://flukeout.github.io/" rel="nofollow noreferrer">CSS Diner</a> teaches me (I think) that "div.tb_strip" is a valid CSS selector to capture this table (and possibly other junk).  And indeed, using Firebug's CSS selector, I see the full path:</p>
  
  <pre><code># Use Firebug "Copy CSS Path" and paste into table_path
  table_path &lt;- "html body#gsr.srp.tbo.vasq div#main div#cnt.big div.mw div#rcnt div.col div#center_col div#res.med div#search div div#ires ol#rso li.g.tpo.knavi.obcontainer div.kp-blk div#uid_0.r-iCGI_bFBahQE.xpdbox.xpdopen div div.lr_container.mod div#lr_tab_unit_uid_1.tb_u.r-igQv_rxlT08k div.tb_view div.tb_strip"
  </code></pre>
  
  <p>However, the following attempt to access this table fails due to <code>html_nodes</code> returning an empty list. </p>
  
  <pre><code>( standings &lt;- g_search %&gt;% 
      html_nodes("div.tb_strip") %&gt;% 
      html_table() 
    ) #returns empty list
  </code></pre>
  
  <p>The content does not seem to be making it into g_search, so I don't know yet whether the CSS selector worked.</p>
  
  <pre><code>grep("tb_strip",html_text(read_html("http://www.google.com/?q=mlb+standings")) ) # empty
  </code></pre>
  
  <p>Where did it go?</p>
  
  <p>TYVM</p>