Skip to content

Instantly share code, notes, and snippets.

@felipedavi
Created June 30, 2024 15:28
Show Gist options
  • Save felipedavi/ce6a5ed89119db3286a6039c0767d5fc to your computer and use it in GitHub Desktop.
Save felipedavi/ce6a5ed89119db3286a6039c0767d5fc to your computer and use it in GitHub Desktop.
Bitcoin in Real (Google Finance - Web scraping - Python)
#!/usr/bin/env python3
import requests, re
from bs4 import BeautifulSoup
url = 'https://www.google.com/finance/quote/BTC-BRL'
headers = {
'Accept-Language': 'pt-BR'
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
soup = BeautifulSoup(response.text, 'html.parser')
price_element = soup.find('div', attrs={'class': 'YMlKec fxKbKc'})
bitcoin_price = price_element.text.strip()
print(f'R$ {bitcoin_price}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment