Skip to content

gsoaresdz/coin-market-cap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 

Repository files navigation

CoinMarketCap API Scraper

Github top language Github language count Repository size

About   |   Features   |   Technologies   |   Requirements   |   Execution   |   License   |   Author


🎯 About

This project is a Python script that automates the retrieval of cryptocurrency prices from the web and stores the results in a DataFrame. The script utilizes the following libraries:

  • pandas: for data manipulation.
  • beautifulsoup4: for web scraping.
  • requests: for making HTTP requests.

📝 IDE and Python Version

The script was developed using Jupyter Notebook with Python version 3.8.

📝 Business Rules

The script operates as follows:

  1. Accesses the CoinMarketCap webpage.
  2. Collects the prices of specified cryptocurrencies.
  3. Stores the results in a DataFrame.

📝 Steps Executed in the Code

The code is divided into two main parts:

  • Accessing the CoinMarketCap webpage
  • Automating Price Retrieval

📝 Accessing the CoinMarketCap Page

The first part of the code accesses the CoinMarketCap webpage to retrieve cryptocurrency information. The following code shows how the page is accessed:

import requests
from bs4 import BeautifulSoup

link = 'https://coinmarketcap.com/'
requisicao = requests.get(link)
site = BeautifulSoup(requisicao.text, 'html.parser')

✨ Features

The second part of the code automates the price retrieval for cryptocurrencies. The code operates as follows:

✔️ Feature 1: Accesses the CoinMarketCap page and collects data for listed cryptocurrencies.

✔️ Feature 2: Organizes the data into a pandas DataFrame.

The following code shows how the data is collected and organized:

import re
import pandas as pd

tbody = site.find('tbody')
linhas = tbody.find_all('tr')

moedas = {}

for linha in linhas:
  try:
    nome = linha.find(class_='kKpPOn').text
    codigo = linha.find(class_='coin-item-symbol').text
    valores = linha.find_all(string=re.compile('\$'))
    preco = valores[0]
    percentuais = linha.find_all(string=re.compile('%'))

    for i, percentual in enumerate(percentuais):
      if 'bQjSqS' in percentual.parent["class"]:
        percentuais[i] = "-" + str(percentual)

    var_1h = percentuais[0]
    var_24h = percentuais[1]
    var_7d =  percentuais[2]

    market_cap = valores[2]
    volume = valores[3]
    dic = {"nome": nome, "codigo": codigo, "preco": preco, "var_1h": var_1h, "var_24h": var_24h, "var_7d": var_7d,"market_cap": market_cap, "volume": volume}
    moedas[nome] = dic
  except AttributeError:
    break

df = pd.DataFrame(moedas)
display(df)

🚀 Technologies

The following tools were used in this project:

✅ Requirements

Before starting 🏁, make sure you have Git and Python installed.

🏁 Execution

# Clone the project
$ git clone https://github.com/gsoaresdz/coin-market-cap.git

# Run the script
$ jupyter notebook main.ipynb

📝 Notes

  • This script was developed for educational purposes. It is not recommended to use the script for commercial purposes without proper authorization from the websites.
  • The script can be modified to meet different needs, such as changing the XPath selectors or adding new functionalities.

📝 License

This project is under the MIT license. For more details, see the LICENSE file.

Made with ❤️ by gsoaresdz

Back to top

About

💲Data extraction for each currency listed on CoinMarketCap.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published