mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-07 01:41:17 +00:00
Fix etf function get_all_names_symbols (#2467)
* fix etf scrapping * remove unused import * fix stockanalysis tests
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
"""Stockanalysis.com/etf Model"""
|
||||
__docformat__ = "numpy"
|
||||
|
||||
import json
|
||||
import logging
|
||||
from typing import List, Tuple
|
||||
|
||||
@@ -26,15 +25,23 @@ def get_all_names_symbols() -> Tuple[List[str], List[str]]:
|
||||
etf_names: List[str]
|
||||
List of all available etf names
|
||||
"""
|
||||
|
||||
etf_symbols = []
|
||||
etf_names = []
|
||||
|
||||
r = requests.get(
|
||||
"https://stockanalysis.com/etf/", headers={"User-Agent": get_user_agent()}
|
||||
)
|
||||
soup2 = bs(r.text, "html.parser")
|
||||
script = soup2.find("script", {"type": "application/json"})
|
||||
table = soup2.find("table", attrs={"class": "svelte-v47wb2"})
|
||||
table_body = table.find("tbody")
|
||||
rows = table_body.find_all("tr")
|
||||
for row in rows:
|
||||
cols = row.find_all("td")
|
||||
cols = [ele.text.strip() for ele in cols]
|
||||
etf_symbols.append(cols[0])
|
||||
etf_names.append(cols[1])
|
||||
|
||||
etfs = pd.DataFrame(json.loads(script.string)[1]["data"]["data"])
|
||||
etf_symbols = etfs.s.to_list()
|
||||
etf_names = etfs.n.to_list()
|
||||
return etf_symbols, etf_names
|
||||
|
||||
|
||||
|
||||
@@ -3,19 +3,3 @@
|
||||
1,CRAK,VanEck Vectors Oil Refiners ETF
|
||||
2,DBO,Invesco DB Oil Fund
|
||||
3,DIG,ProShares Ultra Oil & Gas
|
||||
4,DRIP,Direxion Daily S&P Oil & Gas Exp. & Prod. Bear 2X Shares
|
||||
5,DUG,ProShares UltraShort Oil & Gas
|
||||
6,FTXN,First Trust Nasdaq Oil & Gas ETF
|
||||
7,GUSH,Direxion Daily S&P Oil & Gas Exp. & Prod. Bull 2X Shares
|
||||
8,IEO,iShares U.S. Oil & Gas Exploration & Production ETF
|
||||
9,IEZ,iShares U.S. Oil Equipment & Services ETF
|
||||
10,OIH,VanEck Vectors Oil Services ETF
|
||||
11,OILK,ProShares K-1 Free Crude Oil Strategy ETF
|
||||
12,ONG,Direxion Daily Oil Services Bull 2X Shares
|
||||
13,PXJ,Invesco Dynamic Oil & Gas Services ETF
|
||||
14,SCO,ProShares UltraShort Bloomberg Crude Oil
|
||||
15,UCO,ProShares Ultra Bloomberg Crude Oil
|
||||
16,USL,United States 12 Month Oil Fund
|
||||
17,USO,United States Oil Fund
|
||||
18,XES,SPDR S&P Oil & Gas Equipment & Services ETF
|
||||
19,XOP,SPDR S&P Oil & Gas Exploration & Production ETF
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user