Skip to content

Instantly share code, notes, and snippets.

@wilmeragsgh
Last active May 8, 2024 01:55
Show Gist options
  • Save wilmeragsgh/b31c54ba0c28467e7fe799aee8568f4e to your computer and use it in GitHub Desktop.
Save wilmeragsgh/b31c54ba0c28467e7fe799aee8568f4e to your computer and use it in GitHub Desktop.
Get value from different currencies to Venezuelan Bolivar from BCV
"""Get value from different currencies to Venezuelan Bolivar from BCV"""
import requests
from pprint import pprint
from bs4 import BeautifulSoup
# Most params
url = 'https://www.bcv.org.ve/'
exchanges_pairs_selector = {'class_': 'row recuadrotsmc'}
exchanges_date_selector = {'name': 'span', 'class_': 'date-display-single'}
# URL get call
response = requests.get(url)
# Check for successful response.
if response.status_code == 200:
# Parse the HTML content using BeautifulSoup.
soup = BeautifulSoup(response.content, 'html.parser')
# Find all elements with the class "item".
items = soup.find_all(**exchanges_pairs_selector)
exchanges = []
exchange_date = (
soup
.find(**exchanges_date_selector)
.attrs['content']
)
# Util functions
clean_string = lambda x: x.text.strip()
clean_value = lambda x: float(clean_string(x).replace(',', '.'))
for item in items:
exchanges.append({
"exchange_name": clean_string(item.select('span')[0]),
"exchange_value": clean_value(item.select('strong')[0]),
"exchange_date": exchange_date
})
pprint(exchanges)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment