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.
JavaScript
x
11
11
1
import requests
2
from bs4 import BeautifulSoup
3
4
url = "https://solanamonkeysclub.com/#/#mint"
5
6
response = requests.get(url)
7
response.encoding = response.apparent_encoding
8
soup = BeautifulSoup(response.text, 'html.parser')
9
new_elems = str(soup.select('.ant-card-body'))
10
print(f'{"new_elem":10} : {new_elems}')
11
Advertisement
Answer
As the url is dynamic,I use selenium with bs4 and getting the follwing output:
Code:
JavaScript
1
16
16
1
import requests
2
from bs4 import BeautifulSoup
3
import time
4
from selenium import webdriver
5
6
7
driver = webdriver.Chrome('chromedriver.exe')
8
url = "https://solanamonkeysclub.com/#/#mint"
9
driver.get(url)
10
time.sleep(8)
11
12
soup = BeautifulSoup(driver.page_source, 'html.parser')
13
new_elems = soup.select('.ant-card-body')
14
for new_elem in new_elems:
15
print(f'{"new_elem":10} : {new_elem.text}')
16
OUTPUT:
JavaScript
1
3
1
new_elem : 0
2
new_elem : 0
3