Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. <p>Example of a paragraph element.</p>
  2. <ul>
  3. <li>Coffee</li>
  4. <li>Tea</li>
  5. <li>Milk</li>
  6. </ul>
  7.  
  8. p: Example of a paragraph element.
  9. ul:
  10. li:Coffee
  11. li:Tea
  12. li:Milk
  13.  
  14. html = '''<p>Example of a paragraph element.</p>
  15. <ul>
  16. <li>Coffee</li>
  17. <li>Tea</li>
  18. <li>Milk</li>
  19. </ul>'''
  20.  
  21.  
  22. from bs4 import BeautifulSoup
  23.  
  24. soup = BeautifulSoup(html, 'html.parser')
  25.  
  26. for tag in soup.find_all():
  27. print (tag.name + ':' + tag.text)
  28.  
  29. p:Example of a paragraph element.
  30. ul:
  31. Coffee
  32. Tea
  33. Milk
  34.  
  35. li:Coffee
  36. li:Tea
  37. li:Milk
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement