Skip to content
Advertisement

BeautifulSoup.select classname not working

I am trying to find tags by CSS class, using BeautifulSoup. Read documentation and tried different ways but the below code returns new_elem : []. Could you help me understand what I am doing wrong? Thanks.

import requests
from bs4 import BeautifulSoup

url = "https://solanamonkeysclub.com/#/#mint"

response = requests.get(url)
response.encoding = response.apparent_encoding
soup = BeautifulSoup(response.text, 'html.parser')
new_elems = str(soup.select('.ant-card-body'))
print(f'{"new_elem":10} : {new_elems}')

Advertisement

Answer

As the url is dynamic,I use selenium with bs4 and getting the follwing output:

Code:

import requests
from bs4 import BeautifulSoup
import time
from selenium import webdriver


driver = webdriver.Chrome('chromedriver.exe')
url = "https://solanamonkeysclub.com/#/#mint"
driver.get(url)
time.sleep(8)

soup = BeautifulSoup(driver.page_source, 'html.parser')
new_elems = soup.select('.ant-card-body')
for new_elem in new_elems:
    print(f'{"new_elem":10} : {new_elem.text}')

OUTPUT:

new_elem   : 0
new_elem   : 0
Advertisement