Last active
May 23, 2019 03:27
-
-
Save spceaza/2f7a651edf02a084d507b9107ecdead7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
base_url = "https://etfdb.com/data_set/?tm=40284&cond={%22by_etf%22:1272}&no_null_sort=true&count_by_id=&sort=weight&order=desc&limit=15&offset=" | |
CleanString = function( string ) | |
{ | |
result = gsub( "<a.*stock/", "", string ) | |
gsub( "/.*", "", result ) | |
} | |
WeightsFromUrl = function( json_url ) | |
{ | |
json_data = jsonlite::read_json( json_url ) | |
weights_data = sapply( json_data$rows , function( x ) x$weight ) | |
holdings_data = sapply( json_data$rows , function( x ) CleanString( x$holding ) ) | |
data.frame(weights_data, holdings_data) | |
} | |
lapply( paste0( base_url, ( 0:2 ) * 15 ), WeightsFromUrl ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment