title: Extracting a section of text from html using rvest
body: <p>I am trying to extract specific references from <em>PubMed</em> pages like this one: [https://pubmed.ncbi.nlm.nih.gov/35867413]. I'm using <code>XML</code> and <code>rvest</code>. Here's a simplified extract from a downloaded web page:</p>
  <pre><code>text = '&lt;!DOCTYPE html&gt; 
  &lt;html lang=&quot;en&quot; &gt; 
  &lt;div class=&quot;references&quot; id=&quot;references&quot;&gt;
  &lt;h4 class=&quot;refs-list-title&quot;&gt;References to studies included in this review&lt;/h4&gt;
  &lt;div class=&quot;refs-list&quot;&gt;
  &lt;h5 class=&quot;refs-list-title&quot;&gt;Ahn 2008&lt;/h5&gt;
  &lt;h5 class=&quot;refs-list-title&quot;&gt;Al‐Shehr 2020&lt;/h5&gt;
  &lt;h4 class=&quot;refs-list-title&quot;&gt;References to studies excluded from this review&lt;/h4&gt;
  &lt;div class=&quot;refs-list&quot;&gt;
  &lt;h5 class=&quot;refs-list-title&quot;&gt;Smith 2020&lt;/h5&gt;
  &lt;/html&gt;'
  
  pubmed_page = read_html(text)
  references = xml_find_all(pubmed_page, &quot;.//div[@class='references']&quot;) 
  xml_find_all(references, &quot;.//h4[@class='refs-list-title']&quot;) %&gt;%
    xml_text()
  [1] &quot;References to studies included in this review&quot;  
  [2] &quot;References to studies excluded from this review&quot;
  </code></pre>
  <p>What I want is to just get the first two references, so something like:</p>
  <pre><code>xml_?(references) %&gt;% xml_text()
  [1]Ahn 2008
  [2]Al‐Shehr 2020
  </code></pre>
  <p>So the two lines of text at level h5 under the first h4.</p>