title: How can I drop 2-3 elements from a html node and scrape the rest?
body: <p>To be precise, I have a class, say <strong>A</strong>, that I select via html_nodes in rvest. Now <strong>A</strong> can have many sub-classes and lots of html tags such as <strong>links</strong> and <strong>img</strong> tags. I want to drop some particular classes &amp; tags from <strong>A</strong> while scraping the rest of the data. I do not know the classes for the rest of the data. I do know what I want to blacklist. </p>
  
  <p>The HTML (hypothetical). This tag, <code>&lt;div class="messageContent"&gt;</code> is repeated up to 25 times in the document, with differing content, but the same structure. </p>
  
  <pre><code>&lt;div class="messageContent"&gt;
  &lt;article&gt;
  &lt;blockquote class="messageText SelectQuoteContainer ugc baseHtml"&gt;
  &lt;div class="bbCodeBlock bbCodeQuote" data-author="Generic"&gt;
  
  &lt;aside&gt;
  &lt;div class="attribution type"&gt;Generic said:
  &lt;a href="goto/post?id=32554#post-32754" class="AttributionLink"&gt;&amp;uarr;&lt;/a&gt;
  &lt;/div&gt;
  &lt;blockquote class="quoteContainer"&gt;&lt;div class="quote"&gt;I see what you did there.&lt;/div&gt;&lt;div class="quoteExpand"&gt;Click to expand...&lt;/div&gt;&lt;/blockquote&gt;
  &lt;/aside&gt;
  
  &lt;/div&gt;&lt;img src="styles/default/xenforo/clear.png" class="mceSmilieSprite      mceSmilie9" alt=":o" title="Eek!    :o"/&gt; Really?
  &lt;aside&gt;
  &lt;div class="attribution type"&gt;Generic said:
  &lt;a href="goto/post?id=32554#post-32754" class="AttributionLink"&gt;&amp;uarr;&lt;/a&gt;
  &lt;/div&gt;
  &lt;blockquote class="quoteContainer"&gt;&lt;div class="quote"&gt;I see what you did there.&lt;/div&gt;&lt;div class="quoteExpand"&gt;Click to expand...&lt;/div&gt;&lt;/blockquote&gt;
  &lt;/aside&gt;
  
  &lt;div class="messageTextEndMarker"&gt;&amp;nbsp;&lt;/div&gt;
  &lt;/blockquote&gt;
  &lt;/article&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>SO, the page I'm scraping contains multiple such classes. I do </p>
  
  <pre><code>posts &lt;- page %&gt;%  html_nodes(".messageContent") 
  </code></pre>
  
  <p>This gives me a list of 25 html nodes, each containing variations of the aforementioned html content. </p>
  
  <p>I want to remove everything within the <code>&lt;aside&gt;</code> &amp; <code>&lt;/aside&gt;</code> tags (which can occur at multiple places in the post), and capture the rest of the html via <code>html_text() %&gt;% as.character()</code> </p>
  
  <p>Can I do this with rvest?</p>
  
  <p>Testing out @Mirosław Zalewski 's solution. </p>
  
  <pre><code>test&lt;- page %&gt;% html_node(".messageContent") %&gt;%
            html_nodes(xpath='//*[not(ancestor::aside or name()="aside")]/text()')
  </code></pre>
  
  <p>This returned All of the elements of the page that were not within aside. A bit of fine-tuning, led me to: </p>
  
  <pre><code>page %&gt;% html_nodes(xpath='(//div[@class="messageContent"])[1]//*[not(ancestor::aside or name()="aside")]/text()') %&gt;% html_text() %&gt;% as.character()
  </code></pre>
  
  <p>Iterated over the 25 classes, this gives me exactly what I need. </p>