Last active
December 14, 2020 16:26
-
-
Save hieu-van/0f6e2894a0c10c7809973d2aa195e72c to your computer and use it in GitHub Desktop.
Mã Python lấy giá vàng SJC cho Ledger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import requests | |
import sys | |
from bs4 import BeautifulSoup | |
from datetime import datetime | |
page_url = "https://sjc.com.vn/giavang/textContent.php" | |
page = requests.get(page_url) | |
soup = BeautifulSoup(page.content, 'html.parser') | |
# Lấy giá bán | |
raw_ask_price = soup.table.find_all("tr", limit = 2)[1].find_all("td")[2].text | |
ask_price = raw_ask_price.replace(',', '.') + ' VND' | |
# Lấy ngày giờ cập nhật | |
raw_date = soup.find_all(class_ = "w350 m5l float_left red_text bg_white")[0].text | |
date = datetime.strptime(raw_date, '%I:%M:%S %p %d/%m/%Y') | |
print_date = date.strftime('%d/%m/%Y %H:%M:%S') | |
print('%s %s %s' % (print_date, sys.argv[1], ask_price)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment