For those that don't work in education or aren't aware, there is a measurement for a child's reading level called a <a target="_blank" href="https://lexile.com/">Lexile ® Level</a>.  There are ways in which this level can be retrieved using different reading assessments.  The measurement can be used to match a child's reading level to books that are the same level.  So the company maintains a database of books that they have assigned levels.  There are other assessments that measure how well a child is reading, but I'm not aware of any systems that assign books as comprehensively.  The library at the school I work at lacked <a target="_blank" href="https://lexile.com/">Lexile Levels</a> for their books.  This is unfortunate because of the fact that teachers are not able provide students with books for their respective Lexile Level.  Fortunately though the library had a list of ISBNs for the books.<br><br>On the <a target="_blank" href="https://lexile.com/">Lexile website</a> there is a way to search for books using ISBN numbers to retrieve their Lexile ® Level if the book is available in their database.  Entering every ISBN number available is a task fit for something not human. <br><br><a target="_blank" href="https://cran.r-project.org/web/packages/rvest/rvest.pdf">rvest</a> to the rescue. <br><br>Below is the script to retrieve the Lexile Levels of books if a list of ISBNs is available.  This was an incredible time save provided by some R code and hopefully someone else out there could use it.<br>  <br><table><tr><td> </td></tr><tr><td></td><td>library(<span>rvest</span>) library(httr)</td></tr><tr><td></td><td>library(<span>htmltools</span>)</td></tr><tr><td></td><td>library(<span>dplyr</span>)</td></tr><tr><td></td><td><span><span>#</span>#Prep for things used later</span></td></tr><tr><td></td><td><span>url</span><span>&lt;-</span><span><span>&quot;</span>https://www.lexile.com/fab/results/?keyword=<span>&quot;</span></span></td></tr><tr><td></td><td><span>url2</span><span>&lt;-</span><span><span>&quot;</span>https://lexile.com/book/details/<span>&quot;</span></span></td></tr><tr><td></td><td><span><span>#</span>#CSV file with ISBN numbers</span></td></tr><tr><td></td><td><span>dat1</span><span>&lt;-</span>read.csv(<span><span>&quot;</span>~isbns.csv<span>&quot;</span></span>,<span>header</span><span>=</span><span>FALSE</span>)</td></tr><tr><td></td><td><span><span>#</span>#dat1&lt;-data.frame(dat1[203:634,])</span></td></tr><tr><td></td><td><span>dat</span><span>&lt;-</span>as.character(<span>dat1</span>[,<span>1</span>])%<span>></span>%trimws()</td></tr><tr><td></td><td><span><span>#</span>#dat&lt;-dat[41:51]</span></td></tr><tr><td></td><td><span>blank</span><span>&lt;-</span>as.character(<span><span>&quot;</span>NA<span>&quot;</span></span>)</td></tr><tr><td></td><td><span>blank1</span><span>&lt;-</span>as.character(<span><span>&quot;</span>NA<span>&quot;</span></span>)</td></tr><tr><td></td><td><span><span>#</span>#blank2&lt;-as.character(&quot;NA&quot;)</span></td></tr><tr><td></td><td><span><span>#</span>#blank3&lt;-as.character(&quot;NA&quot;)</span></td></tr><tr><td></td><td><span>all</span><span>&lt;-</span><span>data.frame</span>(<span><span>&quot;</span>A<span>&quot;</span></span>,<span><span>&quot;</span>B<span>&quot;</span></span>,<span><span>&quot;</span>C<span>&quot;</span></span>)</td></tr><tr><td></td><td>colnames(<span>all</span>)<span>&lt;-</span>c(<span><span>&quot;</span>name<span>&quot;</span></span>,<span><span>&quot;</span>lexiledat<span>&quot;</span></span>,<span><span>&quot;</span>num<span>&quot;</span></span>)</td></tr><tr><td></td><td><span>all</span><span>&lt;-</span><span>data.frame</span>(<span>all</span>[<span>-</span><span>1</span>,])</td></tr><tr><td></td><td></td></tr><tr><td></td><td><span>for</span>(<span>i</span> <span>in</span> <span>dat</span>) {</td></tr><tr><td></td><td> </td></tr><tr><td></td><td><span>sites</span><span>&lt;-</span>paste(<span>url</span>,<span>i</span>,<span>sep</span><span>=</span><span><span>&quot;</span><span>&quot;</span></span>)</td></tr><tr><td></td><td></td></tr><tr><td></td><td><span>x</span> <span>&lt;-</span> GET(<span>sites</span>, add_headers(<span><span>'</span>user-agent<span>'</span></span> <span>=</span> <span><span>'</span>r<span>'</span></span>))</td></tr><tr><td></td><td></td></tr><tr><td></td><td><span>webpath</span><span>&lt;-</span><span>x</span><span>$</span><span>url</span>%<span>></span>%<span>includeHTML</span>%<span>></span>%read_html()</td></tr><tr><td></td><td></td></tr><tr><td></td><td><span><span>#</span>#Book Name</span></td></tr><tr><td></td><td><span>name</span><span>&lt;-</span><span>webpath</span>%<span>></span>%html_nodes(<span>xpath</span><span>=</span><span><span>&quot;</span>///div[2]/div/div[2]/h4/a<span>&quot;</span></span>)%<span>></span>%html_text()%<span>></span>%trimws()</td></tr><tr><td></td><td></td></tr><tr><td></td><td><span><span>#</span>#Lexile Range</span></td></tr><tr><td></td><td><span>lexile</span><span>&lt;-</span><span>webpath</span>%<span>></span>%html_nodes(<span>xpath</span><span>=</span><span><span>&quot;</span>///div[2]/div/div[3]/div[1]<span>&quot;</span></span>)%<span>></span>%html_text()%<span>></span>%trimws()%<span>></span>%as.character()</td></tr><tr><td></td><td></td></tr><tr><td></td><td><span><span>#</span>#CSS change sometimes </span></td></tr><tr><td></td><td><span>lexiledat</span><span>&lt;-</span>ifelse(is.na(<span>lexile</span>[<span>2</span>])<span>==</span><span>TRUE</span>,<span>lexile</span>,<span>lexile</span>[<span>2</span>])</td></tr><tr><td></td><td></td></tr><tr><td></td><td><span>test1</span><span>&lt;-</span><span>data.frame</span>(<span>lexiledat</span>,<span>NA</span>)</td></tr><tr><td></td><td></td></tr><tr><td></td><td><span><span>#</span>#Breaks every now and then when adding Author/Pages</span></td></tr><tr><td></td><td><span><span>#</span>#Author Name</span></td></tr><tr><td></td><td><span><span>#</span>#author&lt;-webpath%>%html_nodes(xpath='///div[2]/div/div[2]/span')%>%html_text()%>%as.character()%>%trimws()</span></td></tr><tr><td></td><td></td></tr><tr><td></td><td><span><span>#</span>#author&lt;-sub(&quot;by: &quot;,&quot;&quot;,author)</span></td></tr><tr><td></td><td></td></tr><tr><td></td><td><span><span>#</span>#Pages</span></td></tr><tr><td></td><td><span><span>#</span>#pages&lt;-webpath%>%html_nodes(xpath='///div[2]/div/div[2]/div/div[1]')%>%html_text()%>%as.character()%>%trimws()</span></td></tr><tr><td></td><td></td></tr><tr><td></td><td><span><span>#</span>#pages&lt;-sub(&quot;Pages: &quot;,&quot;&quot;,pages)</span></td></tr><tr><td></td><td></td></tr><tr><td></td><td></td></tr><tr><td></td><td><span><span>#</span>#Some books not found, this excludes them and replaces with NA values</span></td></tr><tr><td></td><td><span>df</span><span>&lt;-</span><span>if</span>(is.na(<span>test1</span>)) <span>data.frame</span>(<span>blank</span>,<span>blank1</span>) <span>else</span> <span>data.frame</span>(<span>name</span>,<span>lexiledat</span>,<span>stringsAsFactors</span> <span>=</span> <span>FALSE</span>)</td></tr><tr><td></td><td></td></tr><tr><td></td><td>colnames(<span>df</span>)<span>&lt;-</span>c(<span><span>&quot;</span>name<span>&quot;</span></span>,<span><span>&quot;</span>lexiledat<span>&quot;</span></span>)</td></tr><tr><td></td><td><span>df</span><span>$</span><span>num</span> <span>&lt;-</span> <span>i</span></td></tr><tr><td></td><td></td></tr><tr><td></td><td><span>all</span><span>&lt;-</span>bind_rows(<span>all</span>,<span>df</span>)</td></tr><tr><td></td><td></td></tr><tr><td></td><td>}</td></tr><tr><td></td><td></td></tr><tr><td></td><td><span>master</span><span>&lt;-</span>rbind(<span>all1</span>,<span>all</span>)</td></tr></table>   <br><a target="_blank" href="https://github.com/justlebeau/Blog-Code/blob/master/LexileLevelScrape.R">Link to code</a><br><br><br>