Web scraping with python, how to print the class of a div

Asked

Viewed 119 times

0

I would like to print the class of a div in Phyton, the code of the site and:

<div class="history-feed__collection">
     <div class="history-feed__card h-card h-card_sm h-card_spades" style="width: 41px; margin-right: 18px; opacity: 1;">
         <div class="h-card__sign">9</div></div>
     <div class="history-feed__card h-card h-card_sm h-card_hearts" style="width: 41px; margin-right: 18px; opacity: 1;">
         <div class="h-card__sign">K</div></div>
     <div class="history-feed__card h-card h-card_sm h-card_diamonds" style="width: 41px; margin-right: 18px; opacity: 1;">
         <div class="h-card__sign">Q</div></div>
     <div class="history-feed__card h-card h-card_sm h-card_clubs" style="width: 41px; margin-right: 18px; opacity: 1;">
         <div class="h-card__sign">2</div></div>


O Codigo que tenho e:

# Importando a BeautifulSoup
from bs4 import BeautifulSoup

# Trocando URL
url = 'https://card.com/game'

# lendo a URL com a urllopen
html = urlopen(url)

# Enfim mostrando o poder da bs4
bs = BeautifulSoup(html, 'lxml')

# Imprimindo
print(bs.find('div', class_='history-feed__card h-card h-card_sm h-card_spades'))

# Apenas o texto
print(bs.find('div', class_='history-feed__card h-card h-card_sm h-card_spades').text)


I wanted to take the class from the div, like "history-feed__card h-card h-card_sm h-card_spades" from the div and print it

  • Got a little confused, you want to print the class or text of the div?

  • print the class

  • Not just print her out? print('history-feed__card h-card h-card_sm h-card_spades')

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.