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)!
from bs4 import BeautifulSoup
soup = BeautifulSoup('<div id="left"><ul><li>"I want this text"<a href="someurl.com"> I don\'t want this text</a><p>I don\'t want this either</li><li>"Good"<a href="someurl.com"> Not Good</a><p> Not Good either</li></ul></div>', "html5lib")
x = soup.select('ul > li')
for i in x:
"I want this text" I don't want this textI don't want this either
"Good" Not Good Not Good either
"I want this text"
One option would be to get the first element of the
for i in x: print(i.contents)
Another - find the first text node:
for i in x: print(i.find(text=True))
Both would print:
"I want this text" "Good"