I wrote a program that saves the page source from https://www.coinbase.com/price to pyt.txt. How can I parse the price of bitcoin from this text file and have it be printed?
So far, I have learned that the 42nd p tag in the page source is the one that holds the price of bitcoin. So, my code to attempt to extract that value and print it is as follows:
import bs4
file = open('location/pyt.txt', 'r')
soup = bs4.BeautifulSoup(file, 'lxml')
for btc in soup.find_all('p'):
print(btc[41])
file.close()
When I run it I get the error:
return self.attrs[key]
KeyError: 41
After many hours of YouTubing and googling it seems that BeautifulSoup would work best but I just can't seem to figure it out.