syntax

1
2
#find span element
soup.span


1
2
#find all span
fnd_all('span')

find span element Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
from bs4 import BeautifulSoup
#html source
html_source = '''
<div  id="test">
     <h2> <span>hello</span>paragraph1</h2>
</div>
'''

soup = BeautifulSoup(html_source, 'html.parser')


#find span
print(soup.h2)

output

1
<span>hello</span>  

find all span elements example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
from bs4 import BeautifulSoup
#html source
html_source = '''
<div  id="test">
     <h2> <span>hello</span>paragraph1</h2>
     <h2> <span>hello1</span>paragraph2</h2>
     <h2> <span>hello2</span>paragraph3</h2>
</div>
'''

soup = BeautifulSoup(html_source, 'html.parser')

#find all sppan
print(soup.find_all('span'))

output

1
[<span>hello</span>, <span>hello1</span>, <span>hello2</span>]                                                                        

English today is not an art to be mastered it's just a tool to use to get a result