I'm trying to scrape coinmarketcap.com just to get an update of a certain currency price, also just to learn how to web scrape. I'm still a beginner and can't figure out where I'm going wrong, because whenever I try to run it, it just tells me there are none. Although I know that line does exist. Any help is appreciated!
import requests
from bs4 import BeautifulSoup
url = 'https://coinmarketcap.com/currencies/electroneum/'
response = requests.get(url)
html = response.content
soup = BeautifulSoup(html, 'html.parser')
price = soup.find('data-currency-price data-usd=')
print (price)
You should try to be more specific in how you want to FIND the item.
you currently are using
soup.find('')
I am not sure what you have put inside this as you wrote data-currency-price data-usd= Is that an ID a class name?why not try finding the item using an ID.
or find by tag
or something like this
You can use the class attribute to get the value.
Output :
If you are going to be doing alot of this consider doing a single call using the official API and get all the prices. Then extract what you want. The following is from the site with an amendment by me to show the desired value for electroneum. The API guidance shows how to retrieve one at a time as well, though that requires a higher plan than the basic.
You can always deploy a loop and check against a desired list e.g.
For your current example:
You can use an attribute selector for
data-currency-value
Look for ID better,or search through
soup.find_all(text="data-currency-price data-usd")[1].text
You can get the value like this: