title: How to extract the text inside a tag with BeautifulSoup in Python?
body: <p>Supposing I have an html string like this:</p>
  
  <pre><code>&lt;html&gt;
      &lt;div id="d1"&gt;
          Text 1
      &lt;/div&gt;
      &lt;div id="d2"&gt;
          Text 2
          &lt;a href="http://my.url/"&gt;a url&lt;/a&gt;
          Text 2 continue
      &lt;/div&gt;
      &lt;div id="d3"&gt;
          Text 3
      &lt;/div&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I want to extract the content of <code>d2</code> that is <strong>NOT</strong> wrapped by other tags, skipping <code>a url</code>. In other words I want to get such result:</p>
  
  <pre><code>Text 2
  Text 2 continue
  </code></pre>
  
  <p>Is there a way to do it with BeautifulSoup?</p>
  
  <p>I tried this, but it is not correct:</p>
  
  <pre><code>soup = BeautifulSoup(html_doc, 'html.parser')
  s = soup.find(id='d2').text
  print(s)
  </code></pre>