Home > OS >  How do I get this attribute in python BeutifulSoup?
How do I get this attribute in python BeutifulSoup?

Time:09-01

Its probably just a simple fix but all the methods I have looked at to get the Dogecoin price off of a this website gets the price, but with all of this other stuff. How do I just get the price without it inhibiting its ability to refresh? Here is what I currently have...

from bs4 import BeautifulSoup
import requests

url = 'https://www.coindesk.com/price/dogecoin/'

result = requests.get(url)
doc = BeautifulSoup(result.text, 'html.parser')

prices = doc.find_all(text="$")
parent = prices[10].parent
print(parent)

CodePudding user response:

If you only want the text of an element, all you have to do is:

print(parent.text)

BeautifulSoup documentation can be found at https://beautiful-soup-4.readthedocs.io/en/latest/index.html

  • Related