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?
– TiagoA
print the class
– Gustavo
Not just print her out?
print('history-feed__card h-card h-card_sm h-card_spades')
– TiagoA