Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from bs4 import BeautifulSoup
- html_str = """
- <html>
- <head>
- <title>The Avengers</title>
- </head>
- <body>
- <h1>Movies</h1>
- <p>The Avengers (2012)</p>
- <p>Avengers: Age of Ultron (2015)</p>
- <p>Avengers: Infinity War (2018)</p>
- <p>Avengers: Endgame (2019)</p>
- </body>
- </html>
- """
- soup = BeautifulSoup(html_str)
- print(soup.select('html > body > p:nth-of-type(4)')[0].text)
- print(soup.select('p:nth-of-type(4)')[0].text)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement