mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-24 18:22:43 +00:00
* Updated try except * Added patch for fraud * Updated tests * Fix * Attempting to resolve test issue * Fixed again Co-authored-by: Colin Delahunty <colindelahunty@Colins-Air.indiana.edu>
51 lines
1.2 KiB
Python
51 lines
1.2 KiB
Python
"""DeFi Pulse model"""
|
|
__docformat__ = "numpy"
|
|
|
|
import requests
|
|
from bs4 import BeautifulSoup
|
|
import pandas as pd
|
|
|
|
from gamestonk_terminal.helper_funcs import try_except
|
|
|
|
|
|
@try_except
|
|
def get_defipulse_index() -> pd.DataFrame:
|
|
"""Scrapes data from DeFi Pulse with all DeFi Pulse crypto protocols.
|
|
[Source: https://defipulse.com/]
|
|
|
|
Returns
|
|
-------
|
|
pd.DataFrame
|
|
List of DeFi Pulse protocols.
|
|
"""
|
|
|
|
req = requests.get("https://defipulse.com/")
|
|
result = req.content.decode("utf8")
|
|
soup = BeautifulSoup(result, features="lxml")
|
|
table = soup.find("tbody").find_all("tr")
|
|
|
|
list_of_records = []
|
|
for row in table:
|
|
row_elements = []
|
|
for element in row.find_all("td"):
|
|
text = element.text
|
|
row_elements.append(text)
|
|
list_of_records.append(row_elements)
|
|
|
|
df = pd.DataFrame(
|
|
list_of_records,
|
|
columns=[
|
|
"x",
|
|
"Rank",
|
|
"Name",
|
|
"Chain",
|
|
"Category",
|
|
"TVL",
|
|
"Change_1D",
|
|
],
|
|
)
|
|
df["Rank"] = df["Rank"].apply(lambda x: int(x.replace(".", "")))
|
|
|
|
df.drop("x", axis=1, inplace=True)
|
|
return df
|