In this post we'll find all p tagq in html source and get their value

syntax

1
soup.find_all('p')

example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from bs4 import BeautifulSoup
#html source
html_source = '''
<div id="test">
     <p>paragraph1</p>
  </div>

  <div id="test">
     <p>paragraph2</p>
  </div>

  <div id="test">
     <p>paragraph3</p>
  </div>

  <div id="test">
     <p>paragraph4</p>
  </div> 

  <div id="test">
     <p>paragraph5</p>
  </div>

  <div id="test">
     <p>paragraph6</p>
  </div>
'''

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

#finding all 'p'
find_all = soup.find_all('p')
print(find_all)   

output

1
[<p>paragraph1</p>, <p>paragraph2</p>, <p>paragraph3</p>, <p>paragraph4</p>, <p>paragraph5</p>, <p>paragraph6</p>]      

print 'p' tags value

1
2
for i in find_all:
    print(i.string)    

output

1
2
3
4
5
6
paragraph1                                                                                                                            
paragraph2                                                                                                                            
paragraph3                                                                                                                            
paragraph4                                                                                                                            
paragraph5                                                                                                                            
paragraph6     

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