SHARE
TWEET

Untitled

a guest May 19th, 2019 46 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top