Advertisement
Guest User

Untitled

a guest
May 19th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. from bs4 import BeautifulSoup
  2.  
  3. html_str = """
  4. <html>
  5. <head>
  6. <title>The Avengers</title>
  7. </head>
  8. <body>
  9. <h1>Movies</h1>
  10. <p>The Avengers (2012)</p>
  11. <p>Avengers: Age of Ultron (2015)</p>
  12. <p>Avengers: Infinity War (2018)</p>
  13. <p>Avengers: Endgame (2019)</p>
  14. </body>
  15. </html>
  16. """
  17.  
  18. soup = BeautifulSoup(html_str)
  19. print(soup.select('html > body > p:nth-of-type(4)')[0].text)
  20. print(soup.select('p:nth-of-type(4)')[0].text)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement