Using BeautifulSoup, how to get text only from the specific selector without the text in the children?
<p>I don't know how to code BeautifulSoup so that it gives me only the text from the selected tag. I get more such as the text of its child(ren)!</p>

<p>For example:</p>

<pre><code>from bs4 import BeautifulSoup
soup = BeautifulSoup('&lt;div id="left"&gt;&lt;ul&gt;&lt;li&gt;"I want this text"&lt;a href="someurl.com"&gt; I don\'t want this text&lt;/a&gt;&lt;p&gt;I don\'t want this either&lt;/li&gt;&lt;li&gt;"Good"&lt;a href="someurl.com"&gt; Not Good&lt;/a&gt;&lt;p&gt; Not Good either&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;', "html5lib") 
x = soup.select('ul &gt; li')
for i in x:
    print(i.text)
</code></pre>

<p>Output: </p>

<blockquote>
  <p>"I want this text" I don't want this textI don't want this either</p>
  
  <p>"Good" Not Good Not Good either</p>
</blockquote>

<p>Desired Output:</p>

<blockquote>
  <p>"I want this text" </p>
  
  <p>"Good"</p>
</blockquote>

<p>One option would be to get the first element of the <a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/#contents-and-children" rel="nofollow"><code>contents</code> list</a>:</p>

<pre><code>for i in x:
    print(i.contents[0])
</code></pre>

<p>Another - find the first <em>text node</em>:</p>

<pre><code>for i in x:
    print(i.find(text=True))
</code></pre>

<p>Both would print:</p>

<pre><code>"I want this text"
"Good"
</code></pre>

python web-scraping beautifulsoup