Ukrayna merkez bankası rate çekimi

Selamlar;

üzerinden date=yyyy-mm-dd olarak rate çekmeye çalışıyorum. Html olarak satır satır parse edebilirim bunda sorun yok fakat alt kısımda export to xlslx olarak bir buton var buna basınca ilgili güne ait rateler xlsx olarak indiriliyor. Fakat bu butona basınca oluşan link değişken belli bir algoritmaya göre generate ediliyor sanırım. Bu linke basınca save as dialog’u çıkıyor bu nedenle ilgili linki yakalayamıyorum. yakalayabilsem dosyayı arka planda download edip import işlemi yapabilecem. Var mıdır önerisi olan?

çalıştırdıkları JS kodu şu aşağı yukarı, belki yardımı olur:

var i = document.querySelector("ul.breadcrumbs> li:last-child >span").innerHTML;
var t, e, n, a, r;
t = document.documentElement.lang, e = [], n = [], a = $("#exchangeDate").html(), r = $("#exchangeRates th").length, $("#exchangeRates th").each(function(n, a) {
    0 == n ? (e.push("uk" == t ? "Дата" : "Date"), e.push("uk" == t ? "Час" : "Time"), e.push($(a).html())) : n == r - 1 ? e.push($(a).html().replace(/(<([^>]+.*)>)/gi, "")) : e.push($(a).html().replace(/(<([^>]+)>)/gi, ""))
}), $("#exchangeRates tbody tr").each(function(t, e) {
    var r = [];
    $(this).find("td").each(function(t, e) {
        0 == t ? (r.push(a), r.push("00.00"), r.push($(e).html().replace(/(<([^>]+)>)/gi, ""))) : r.push($(e).html().replace(/(<([^>]+)>)/gi, ""))
    }), n.push(r)
}), $.ajax({
    type: "POST",
    url: ("uk" === t ? "/ua" : "/en") + "/export-table/xlsx",
    data: {
        data: n,
        header: e,
        date: a
    },
    success: function(e) {
        var n = ("uk" === t ? "/ua" : "/en") + "/export-table/download?tempfile=" + e[0] + "&filename=" + i + ".xlsx";
        window.open(n, "_blank")
    }
})

buradan alıntı https://bank.gov.ua/frontend/dist/js/exchangeRates.d72af6d002f41a6d1872.js?v=4

1 Beğeni

çok teşekkür ederim. Bunu nasıl elde ettiğini de yazabilir misin? Ben epey takla atıp ulaşamamıştım.

Öncelikle XLSX sağlayan butonun id’sini not edip sonra sayfanın kaynağında (chrome’da F12+Sources) buna basıldığında ne olacağını belirleyen JS kodunun bulunduğu dosyayı arıyoruz; /frontend/dist/js/exchangeRates...'e koymuşlar. Minify etmişler, biz de geri prettify ediyoruz (şu site ile mesela https://beautifier.io/). Sonrasında açığa çıkan bir nebze de olsa okunabilir koddan butona basıldığında ne olacağını belirleyen fonksiyonu elde ediyoruz

1 Beğeni

Selenium ile yapmak isterseniz, aşağıdaki kodu inceleyebilirsiniz.

import os

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import ElementClickInterceptedException

profile = webdriver.FirefoxProfile()
profile.set_preference("browser.download.folderList", 2) 
profile.set_preference("browser.download.dir", os.getcwd())
profile.set_preference(
    "browser.helperApps.neverAsk.saveToDisk", 
    "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
)
profile.set_preference(
    "browser.helperApps.neverAsk.openFile",
    "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
)

options = Options()
options.add_argument("--headless")
options.add_argument("window-size=1920x1080")

driver = webdriver.Firefox(
    executable_path="./geckodriver/geckodriver", 
    firefox_profile=profile,
    options=options
)
driver.get(
    "https://bank.gov.ua/en/markets/exchangerates?date=2021-02-05&period=daily"
)
while True:
    try:
        element = WebDriverWait(driver, 10).until(
            EC.element_to_be_clickable((By.ID, "xlsx-export"))
        )
        element.click()
        break
    except ElementClickInterceptedException:
        continue
2 Beğeni

Eyvallah sağolun bilgiler için.