Issue
I am relatively new to web scraping using Python, and I am having a lot of difficulty pulling the name value out of an HTML table row on CoinMarketCap.com. Their structure is unfamiliar to me. I have tried several methods, both on stack overflow and on other sites, to no avail. Here is a snippet of their html: https://i.stack.imgur.com/eBamV.png This is the code I currently have:
import requests
from bs4 import BeautifulSoup
page = requests.get("https://coinmarketcap.com/rankings/exchanges/").text
soup = BeautifulSoup(page, features="html.parser")
tags = soup.findAll("div", class_="sc-16r8icm-0 sc-1teo54s-1 dNOTPP")
tables = soup.findChildren('tr')
my_table = tables[0]
rows = my_table.findChildren(['td'])
print(rows)
for row in rows:
cells = row.findChildren('td')
for cell in cells:
value = cell.string
print("the value in this cell is %s" % value)
thanks in advance for any help!
Solution
These sc-16r8icm-0 sc-1teo54s-1 dNOTPP
are three classes separated with spaces. If you need to identify an element by multiple classes, use a selector like this
tags = soup.select("div.sc-16r8icm-0.sc-1teo54s-1.dNOTPP")
Answered By - wallfell00
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.