Python’ın Beautiful Soup kütüphanesini kullanarak Hurriyet/Doviz’den döviz verilerini nasıl kazıyacağınızı ve bunları Microsoft Fabric Lakehouse veya Warehouse’a nasıl depolayacağınızı öğrenin. Adım adım talimatları izleyin, gerekli kütüphaneleri kurun, olası web sayfası yapı değişikliklerini yönetin ve doğru veri alımını etkili tekniklerle sağlayın.

Introduction
Bu makalede, Python’daki Beautiful Soup kütüphanesini kullanarak Hurriyet/Doviz (https://bigpara.hurriyet.com.tr/doviz/) adresinden döviz verilerini kazıyacağız. İlk olarak, aşağıdaki komutlarla gerekli kütüphaneleri kurun:
pip install beautifulsoup4
pip install pandas
Yavaş ağ bağlantılarını yönetmek için, sayfanın tamamen yüklenmesini sağlamak amacıyla kodunuza time.sleep() fonksiyonunu kullanarak bir gecikme ekleyin. Eğer web sayfasının yapısı değişmişse, aşağıda ayrıntılı olarak gösterildiği gibi gerekli öğeleri manuel olarak belirleyip seçin.
Python Kütüphanelerini İçe Aktarma
HTML için Beautiful Soup, Spark bağlayıcısı için spark connector, veri çerçevesi için pandas içe aktarıldı.
import requests
from bs4 import BeautifulSoup
import pandas as pd
import datetime as dt
import com.microsoft.spark.fabric
from com.microsoft.spark.fabric import Constants
Hurriyet/Doviz’e Giriş Yapma
Burada, Hurriyet/Doviz’e giriş için kod yazıyoruz. İlk olarak, URL’ye bir GET isteği gönderiliyor ve ardından HTML belgesi tanımlanıyor:
#Url link
url= 'https://bigpara.hurriyet.com.tr/doviz/'
#Get url
html = requests.get(url)
#parse url
soup = BeautifulSoup(html.text)
Web sitesinde, ABD Doları, Euro ve İngiliz Sterlini div.dovizBar.mBot20 içinde.

Euro Alış(TL) incelendiğinde, değerler span class=value içinde. Bu nedenle her ABD Doları, Euro ve Sterlin değerleri span class=value içinde.

USD, EURO ve STERLIN için HTML’ye sahip olarak. Bilgiyi çıkaralım:
row_value = soup.find_all("span", {"class": "value"})
#usd value
usd=row_value[2].text
dolar=[usd]
#eur value
eur=row_value[5].text
euro=[eur]
#ster value
ster=row_value[8].text
sterlin=[ster]
#current date time
today_datetime = dt.datetime.today()
date_time=[today_datetime]
#current date
today_date = dt.date.today()
date=[today_date]
Ve Python’da pandas kullanmak için bir dataframe oluşturma.
web_currency = pd.DataFrame(
{
"ABD_Doları":dolar,
"EURO":euro,
"STERLIN":sterlin,
"Date":today_date,
"Date_Time":date_time
}
)
web_currency
Çıktı kodu:

Özetle bir kod oluşturalım:
dolar=[]
euro=[]
sterlin=[]
date=[]
date_time=[]
def cur_val():
#Url link
url= 'https://bigpara.hurriyet.com.tr/doviz/'
#Get url
html = requests.get(url)
#parse url
soup = BeautifulSoup(html.text)
#look row values
row_value = soup.find_all("span", {"class": "value"})
#usd value
usd=row_value[2].text
dolar=[usd]
#eur value
eur=row_value[5].text
euro=[eur]
#ster value
ster=row_value[8].text
sterlin=[ster]
#current date time
today_datetime = dt.datetime.today()
date_time=[today_datetime]
#current date
today_date = dt.date.today()
date=[today_date]
web_currency = pd.DataFrame(
{
"ABD_Doları":dolar,
"EURO":euro,
"STERLIN":sterlin,
"Date":today_date,
"Date_Time":date_time
}
)
return(web_currency)
Çıktı kodu:

Artık Hurriyet/Doviz’den verilerimiz var. Bu verileri Lakehouse veya Warehouse içerisine depolayabiliriz. Daha sonra bu veriyi Lakehouse veya Warehouse içindeki test tablosu web_scrap_datas içine aktarabiliriz.
# Make it Spark DataFrame
web_currency = spark.createDataFrame(web_currency)
# Write to Lakehouse (Delta table)
web_currency.write.format("delta").mode("overwrite").save("abfss://DevelopmentWS@onelake.dfs.fabric.microsoft.com/SampleLH.Lakehouse/Tables/web_currency")
#İmport spark connector library
import com.microsoft.spark.fabric
from com.microsoft.spark.fabric import Constants
#Write to Warehouse
web_currency.write.mode("append").synapsesql("SampleWH.dbo.web_currency")
Tüm betikleri tek bir, kullanılabilir ve sürdürülebilir Python uygulamasında birleştirelim:
import requests
from bs4 import BeautifulSoup
import pandas as pd
import datetime as dt
#Spark Connector
import com.microsoft.spark.fabric
from com.microsoft.spark.fabric import Constants
URL = "https://bigpara.hurriyet.com.tr/doviz/"
def fetch_rates() -> pd.DataFrame:
"""
Fetch the currency page, extract USD/EUR/GBP values, and return
a single-row pandas DataFrame with timestamps.
"""
#Request the page (raise on HTTP errors)
r = requests.get(URL, headers=HDRS, timeout=30)
r.raise_for_status()
#Parse HTML with an explicit parser
soup = BeautifulSoup(r.text, "html.parser")
#Select all spans that hold currency values (site-specific)
spans = soup.select("span.value")
if len(spans) < 9:
raise ValueError("Expected at least 9 currency elements (span.value).")
#Extract numbers by position (matches your original logic)
usd = spans[2].get_text(strip=True)
eur = spans[5].get_text(strip=True)
gbp = spans[8].get_text(strip=True)
#Build a one-row DataFrame with dates
now = dt.datetime.now()
today = now.date()
df = pd.DataFrame([{
"ABD_Doları": usd,
"EURO": eur,
"STERLIN": gbp,
"Date": today,
"Date_Time": now
}])
return df
def write_fabric(df: pd.DataFrame):
#Write the DataFrame into Microsoft Fabric (Lakehouse + Warehouse).
# Convert pandas to Spark
spark_df = spark.createDataFrame(df)
#Lakehouse (Delta-Parquet format). Prefer 'append' for ETL runs
spark_df.write.format("delta").mode("append").save(
"abfss://DevelopmentWS@onelake.dfs.fabric.microsoft.com/SampleLH.Lakehouse/Tables/web_currency"
)
#Warehouse table (append new rows)
spark_df.write.mode("append").synapsesql("SampleWH.dbo.web_currency")
def main():
#Fetch & print
web_currency = fetch_rates()
print(web_currency)
#try to write to Lakehouse/Warehouse
try:
write_fabric(web_currency)
print("✔ Write completed.")
except NameError:
#Error
print("Error")
if __name__ == "__main__":
main()
Lakehouse için çıktı:

Warehouse için çıktı:
