Answer the question
In order to leave comments, you need to log in
How to remove unwanted tag and its content using Beatifulsoup?
At the input I have the following code:
<div class="col-xs-6 col">
<strong>Views</strong>
"222"
</div>
r = requests.get(url=url, headers=headers)
soup = Beautifulsoup(r, "lxml")
Views = soup.find("div", class_="col-xs-6-col").text
I get the output: Answer the question
In order to leave comments, you need to log in
You can remove lines with the “strong” tag from the text of the page something like this:
data = '''<div class="col-xs-6 col">
<strong>Views</strong>
"222"
</div>
'''
print(*[''.join([line, '\n']) for line in data.split('\n') if not 'strong>' in line])
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question