Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Clear tag inner content with Beautiful Soup

i have a text like this:

<p>In an article talking about ResNet, there has the following statement</p>\n\n<p><strong>The second, the bottleneck unit, consists of three stacked operations. A series of 1x1, 3x3 and 1x1 convolutions substitute the previous design. The two 1x1 operations are designed for reducing and restoring dimensions. This leaves the 3x3 convolution, in the middle, to operate on a less dense feature vector. Also, BN is applied after each convolution and before ReLU non-linearity.</strong></p>\n\n<p>I am not clear how to understand the statement of <code>This leaves the 3x3 convolution, in the middle, to operate on a less dense feature vector.</code>What does that mean? In specific, what does the <code>less feature vector</code> mean, what causes the generation of this <code>less dense feature vector</code>?</p>\n

I want to remove everything between "code" tag and then extract text from the other tags.

I tried to use

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

soup = BeautifulSoup(text, 'html.parser')
tag = soup.code
tag. Clear()
tag 

but I’ve got: <code></code> as output. Why isn’t the rest of text removed?

>Solution :

Just use .extract().

For example:

from bs4 import BeautifulSoup

soup = BeautifulSoup(sample_html, 'html.parser')
for code_tag in soup.find_all('code'):
    code_tag.extract()

print(soup.getText(strip=True))
print(f"Removed characters from <code> tags: {len(sample_html) - len(soup.getText(strip=True))}")

This, based on your sample, should give you:

In an article talking about ResNet, there has the following statementThe second, the bottleneck unit, consists of three stacked operations. A series of 1x1, 3x3 and 1x1 convolutions substitute the previous design. The two 1x1 operations are designed for reducing and restoring dimensions. This leaves the 3x3 convolution, in the middle, to operate on a less dense feature vector. Also, BN is applied after each convolution and before ReLU non-linearity.I am not clear how to understand the statement ofWhat does that mean? In specific, what does themean, what causes the generation of this?

Removed characters from <code> tags: 222
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading