Advertisement
Sergiyco

bs4 parsing

Sep 11th, 2023
607
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. import requests
  2. from bs4 import BeautifulSoup
  3.  
  4. url = 'https://quotes.toscrape.com/'
  5.  
  6. response = requests.get(url)
  7. soup = BeautifulSoup(response.content, 'html.parser')
  8.  
  9. quotes = soup.find_all('div', {'class': 'quote'})
  10. for quote in quotes:
  11.     text = quote.find('span', {'class': 'text'}).text
  12.     author = quote.find('small', {'class': 'author'}).text
  13.     print(text)
  14.     print(author)
  15.  
  16.     tags = quote.find_next_sibling('a', limit=4)
  17.     for tag in tags:
  18.         print(tag)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement