> For the complete documentation index, see [llms.txt](https://docs.yemreak.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.yemreak.com/arsiv/yazilarim/coinmarketcapten-exchange-icin-currency-bilgilerini-cekme-ve-csvye-kaydetme.md).

# CoinMarketCap'ten Exchange için Currency Bilgilerini Çekme ve CSV'ye Kaydetme

Python ve Selenium kullanarak CoinMarketCap'ten herhangi bir kripto para borsasının bilgilerini nasıl çekeceğinizi ve bu verileri CSV dosyasına nasıl kaydedeceğinizi öğreneceksiniz

## 🔰 Proje Hakkında

{% embed url="<https://www.youtube.com/watch?v=wdbwkXll7Yw>" %}

<figure><img src="https://2136337814-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3IVBqG9Jn8K2viWOpgUm%2Fuploads%2Fgit-blob-c25e3296a33c0c92430105efce16439f8387f9c8%2FSCR-20230504-ucdn.png?alt=media&amp;token=9f3680d8-903e-4361-b72c-c0b9e8a7d65b" alt="" width="563"><figcaption></figcaption></figure>

💥 Python ve Selenium kullanarak CoinMarketCap'ten herhangi bir kripto para borsasının bilgilerini nasıl çekeceğinizi ve bu verileri CSV dosyasına nasıl kaydedeceğinizi öğreneceksiniz. Aşağıda kullanılacak kütüphaneler ve gerekli modüller bulunmaktadır:

📘 Kütüphaneler ve Modüller:

* selenium.webdriver
* csv
* time

🎓 Öğrenecekleriniz: 1️⃣ CoinMarketCap'ten veri çekme 2️⃣ Borsaların bilgilerini işleme ve düzenleme 3️⃣ Verileri bir CSV dosyasına yazma 4️⃣ Sayfada belirli elementlere kaydırma ve daha fazla veri yükleme

📼 Kod örneği ve detaylı açıklamalar için videoyu izleyin!

Etiketler: #python #selenium #coinmarketcap #exchange #web\_scraping #csv #veri\_çekme #veri\_işleme #web\_otomasyon #kripto\_para #kripto\_borsaları #coding #programming #developer #programmer #code

## 📜 Kaynak Kodu

```python
from seleniumwire.webdriver import Chrome
from selenium.webdriver.remote.webelement import WebElement
from selenium.webdriver.common.by import By
from time import sleep
from typing import Any
import csv

MAX_ROW = 60
MAX_ROW_ENLARGED = 200

TABLE_XPATH = '//*[@id="__next"]/div/div[1]/div[2]/div/div/div[2]/table'
BUTTON_XPATH = '//*[@id="__next"]/div/div[1]/div[2]/div/div/div[3]/button'


def scroll_into_elem(elem: WebElement):
    chrome.execute_script("arguments[0].scrollIntoView();", elem)
    sleep(0.5)


def write_to_csv(filename: str, data: list[list[Any]]):
    with open(filename, "w", newline="") as csvfile:
        csvwriter = csv.writer(csvfile)
        csvwriter.writerow(
            ["index", "exchange", "score", "volume", "liqudity", "markets", "coins"]
        )
        for row in data:
            csvwriter.writerow(row)


def fetch_table_rows(
    elem: WebElement, first_row: int, last_row: int
) -> list[list[Any]]:
    """Fetches the table rows from the given element"""
    fetched_rows: list[list[Any]] = []
    for i in range(first_row, last_row + 1):
        row_elem = elem.find_element(By.XPATH, f"tbody/tr[{i}]")
        splitted_row = row_elem.text.split("\n")
        if len(splitted_row) < 9:
            scroll_into_elem(row_elem)
            row_elem = elem.find_element(By.XPATH, f"tbody/tr[{i}]")
        [
            index,
            exchange,
            score,
            volume,
            _,
            liqudity,
            _,
            markets_coins,
        ] = row_elem.text.split("\n")[:8]
        [markets, coins] = markets_coins.split(" ")
        index, score, volume, liqudity, markets, coins = (
            int(index),
            float(score),
            float(volume.replace("$", "").replace(",", "")),
            int(liqudity) if liqudity != "--" else None,
            int(markets),
            int(coins),
        )
        fetched_rows.append([index, exchange, score, volume, liqudity, markets, coins])
    return fetched_rows


if __name__ == "__main__":
    chrome = Chrome()
    chrome.get("https://coinmarketcap.com/rankings/exchanges/")

    elem = chrome.find_element(By.XPATH, TABLE_XPATH)
    rows = fetch_table_rows(elem, 1, MAX_ROW)
    button = chrome.find_element(By.XPATH, BUTTON_XPATH)
    button.click()
    sleep(2)
    rows.extend(fetch_table_rows(elem, MAX_ROW + 1, MAX_ROW_ENLARGED))
    write_to_csv("exchanges.csv", rows)

```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.yemreak.com/arsiv/yazilarim/coinmarketcapten-exchange-icin-currency-bilgilerini-cekme-ve-csvye-kaydetme.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
