Scraping tables on multiple web pages with rvest in R
<p>I am new to web scraping and am trying to scrape tables on multiple web pages. Here is the site: <a href="http://www.baseball-reference.com/teams/MIL/2016.shtml" rel="nofollow">http://www.baseball-reference.com/teams/MIL/2016.shtml</a></p>

<p>I am able to scrape a table on one page rather easily using <code>rvest</code>. There are multiple tables, but I only wanted to scrape the first one, here is my code </p>

<pre><code>library(rvest)
url4 &lt;- "http://www.baseball-reference.com/teams/MIL/2016.shtml"

Brewers2016 &lt;- url4 %&gt;% read_html() %&gt;% 
html_nodes(xpath = '//*[@id="div_team_batting"]/table[1]') %&gt;% 
html_table()   

Brewers2016 &lt;- as.data.frame(Brewers2016)
</code></pre>

<p>The problem is that I want to scrape the first table on the page dating back to 1970. There is a link specifying the previous year at the top left corner just above the table. Does anybody know how I can do this? </p>

<p>I am also open to different ways of doing this, for example, a package other than rvest that might work better. I used rvest because it's the one I started learning. </p>