let
// Fuction that returns the requested page
fnGetTable = (page as number) as table =>
let
// Max allowed item count per page
perpage = 250,
// Retrieve HTML code for the URL formed by using the page number
Source = Web.BrowserContents("https://finance.yahoo.com/crypto/?offset=" & Text.From(page * perpage) & "&count=" & Text.From(perpage)),
// Parse the HTML - I don't like this part but it works
// If Yahoo makes a small change in this table, the this code will not work anymore
TableFromHtml = Html.Table(Source, {{"Column1", "TABLE.W\(100\%\) > * > TR > TH:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(12), TABLE.W\(100\%\) > * > TR > TD[colspan=""""]:not([rowspan]):nth-child(1):nth-last-child(12)"}, {"Column2", "TABLE.W\(100\%\) > * > TR > TH:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(12) + TH:not([colspan]):not([rowspan]):nth-child(2):nth-last-child(11), TABLE.W\(100\%\) > * > TR > TD[colspan=""""]:not([rowspan]):nth-child(1):nth-last-child(12) + TD[colspan=""""]:not([rowspan]):nth-child(2):nth-last-child(11)"}, {"Column3", "TABLE.W\(100\%\) > * > TR > TH:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(12) + TH:not([colspan]):not([rowspan]):nth-child(2):nth-last-child(11) + TH:not([colspan]):not([rowspan]):nth-child(3):nth-last-child(10), TABLE.W\(100\%\) > * > TR > TD[colspan=""""]:not([rowspan]):nth-child(1):nth-last-child(12) + TD[colspan=""""]:not([rowspan]):nth-child(2):nth-last-child(11) + TD[colspan=""""]:not([rowspan]):nth-child(3):nth-last-child(10)"}, {"Column4", "TABLE.W\(100\%\) > * > TR > TH:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(12) + TH:not([colspan]):not([rowspan]):nth-child(2):nth-last-child(11) + TH:not([colspan]):not([rowspan]):nth-child(3):nth-last-child(10) + TH:not([colspan]):not([rowspan]):nth-child(4):nth-last-child(9), TABLE.W\(100\%\) > * > TR > TD[colspan=""""]:not([rowspan]):nth-child(1):nth-last-child(12) + TD[colspan=""""]:not([rowspan]):nth-child(2):nth-last-child(11) + TD[colspan=""""]:not([rowspan]):nth-child(3):nth-last-child(10) + TD[colspan=""""]:not([rowspan]):nth-child(4):nth-last-child(9)"}, {"Column5", "TABLE.W\(100\%\) > * > TR > TH:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(12) + TH:not([colspan]):not([rowspan]):nth-child(2):nth-last-child(11) + TH:not([colspan]):not([rowspan]):nth-child(3):nth-last-child(10) + TH:not([colspan]):not([rowspan]):nth-child(4):nth-last-child(9) + TH:not([colspan]):not([rowspan]):nth-child(5):nth-last-child(8), TABLE.W\(100\%\) > * > TR > TD[colspan=""""]:not([rowspan]):nth-child(1):nth-last-child(12) + TD[colspan=""""]:not([rowspan]):nth-child(2):nth-last-child(11) + TD[colspan=""""]:not([rowspan]):nth-child(3):nth-last-child(10) + TD[colspan=""""]:not([rowspan]):nth-child(4):nth-last-child(9) + TD[colspan=""""]:not([rowspan]):nth-child(5):nth-last-child(8)"}, {"Column6", "TABLE.W\(100\%\) > * > TR > TH:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(12) + TH:not([colspan]):not([rowspan]):nth-child(2):nth-last-child(11) + TH:not([colspan]):not([rowspan]):nth-child(3):nth-last-child(10) + TH:not([colspan]):not([rowspan]):nth-child(4):nth-last-child(9) + TH:not([colspan]):not([rowspan]):nth-child(5):nth-last-child(8) + TH:not([colspan]):not([rowspan]):nth-child(6):nth-last-child(7), TABLE.W\(100\%\) > * > TR > TD[colspan=""""]:not([rowspan]):nth-child(1):nth-last-child(12) + TD[colspan=""""]:not([rowspan]):nth-child(2):nth-last-child(11) + TD[colspan=""""]:not([rowspan]):nth-child(3):nth-last-child(10) + TD[colspan=""""]:not([rowspan]):nth-child(4):nth-last-child(9) + TD[colspan=""""]:not([rowspan]):nth-child(5):nth-last-child(8) + TD[colspan=""""]:not([rowspan]):nth-child(6):nth-last-child(7)"}, {"Column7", "TABLE.W\(100\%\) > * > TR > TH:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(12) + TH:not([colspan]):not([rowspan]):nth-child(2):nth-last-child(11) + TH:not([colspan]):not([rowspan]):nth-child(3):nth-last-child(10) + TH:not([colspan]):not([rowspan]):nth-child(4):nth-last-child(9) + TH:not([colspan]):not([rowspan]):nth-child(5):nth-last-child(8) + TH:not([colspan]):not([rowspan]):nth-child(6):nth-last-child(7) + TH:not([colspan]):not([rowspan]):nth-child(7):nth-last-child(6), TABLE.W\(100\%\) > * > TR > TD[colspan=""""]:not([rowspan]):nth-child(1):nth-last-child(12) + TD[colspan=""""]:not([rowspan]):nth-child(2):nth-last-child(11) + TD[colspan=""""]:not([rowspan]):nth-child(3):nth-last-child(10) + TD[colspan=""""]:not([rowspan]):nth-child(4):nth-last-child(9) + TD[colspan=""""]:not([rowspan]):nth-child(5):nth-last-child(8) + TD[colspan=""""]:not([rowspan]):nth-child(6):nth-last-child(7) + TD[colspan=""""]:not([rowspan]):nth-child(7):nth-last-child(6)"}, {"Column8", "TABLE.W\(100\%\) > * > TR > TH:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(12) + TH:not([colspan]):not([rowspan]):nth-child(2):nth-last-child(11) + TH:not([colspan]):not([rowspan]):nth-child(3):nth-last-child(10) + TH:not([colspan]):not([rowspan]):nth-child(4):nth-last-child(9) + TH:not([colspan]):not([rowspan]):nth-child(5):nth-last-child(8) + TH:not([colspan]):not([rowspan]):nth-child(6):nth-last-child(7) + TH:not([colspan]):not([rowspan]):nth-child(7):nth-last-child(6) + TH:not([colspan]):not([rowspan]):nth-child(8):nth-last-child(5), TABLE.W\(100\%\) > * > TR > TD[colspan=""""]:not([rowspan]):nth-child(1):nth-last-child(12) + TD[colspan=""""]:not([rowspan]):nth-child(2):nth-last-child(11) + TD[colspan=""""]:not([rowspan]):nth-child(3):nth-last-child(10) + TD[colspan=""""]:not([rowspan]):nth-child(4):nth-last-child(9) + TD[colspan=""""]:not([rowspan]):nth-child(5):nth-last-child(8) + TD[colspan=""""]:not([rowspan]):nth-child(6):nth-last-child(7) + TD[colspan=""""]:not([rowspan]):nth-child(7):nth-last-child(6) + TD[colspan=""""]:not([rowspan]):nth-child(8):nth-last-child(5)"}, {"Column9", "TABLE.W\(100\%\) > * > TR > TH:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(12) + TH:not([colspan]):not([rowspan]):nth-child(2):nth-last-child(11) + TH:not([colspan]):not([rowspan]):nth-child(3):nth-last-child(10) + TH:not([colspan]):not([rowspan]):nth-child(4):nth-last-child(9) + TH:not([colspan]):not([rowspan]):nth-child(5):nth-last-child(8) + TH:not([colspan]):not([rowspan]):nth-child(6):nth-last-child(7) + TH:not([colspan]):not([rowspan]):nth-child(7):nth-last-child(6) + TH:not([colspan]):not([rowspan]):nth-child(8):nth-last-child(5) + TH:not([colspan]):not([rowspan]):nth-child(9):nth-last-child(4), TABLE.W\(100\%\) > * > TR > TD[colspan=""""]:not([rowspan]):nth-child(1):nth-last-child(12) + TD[colspan=""""]:not([rowspan]):nth-child(2):nth-last-child(11) + TD[colspan=""""]:not([rowspan]):nth-child(3):nth-last-child(10) + TD[colspan=""""]:not([rowspan]):nth-child(4):nth-last-child(9) + TD[colspan=""""]:not([rowspan]):nth-child(5):nth-last-child(8) + TD[colspan=""""]:not([rowspan]):nth-child(6):nth-last-child(7) + TD[colspan=""""]:not([rowspan]):nth-child(7):nth-last-child(6) + TD[colspan=""""]:not([rowspan]):nth-child(8):nth-last-child(5) + TD[colspan=""""]:not([rowspan]):nth-child(9):nth-last-child(4)"}, {"Column10", "TABLE.W\(100\%\) > * > TR > TH:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(12) + TH:not([colspan]):not([rowspan]):nth-child(2):nth-last-child(11) + TH:not([colspan]):not([rowspan]):nth-child(3):nth-last-child(10) + TH:not([colspan]):not([rowspan]):nth-child(4):nth-last-child(9) + TH:not([colspan]):not([rowspan]):nth-child(5):nth-last-child(8) + TH:not([colspan]):not([rowspan]):nth-child(6):nth-last-child(7) + TH:not([colspan]):not([rowspan]):nth-child(7):nth-last-child(6) + TH:not([colspan]):not([rowspan]):nth-child(8):nth-last-child(5) + TH:not([colspan]):not([rowspan]):nth-child(9):nth-last-child(4) + TH:not([colspan]):not([rowspan]):nth-child(10):nth-last-child(3), TABLE.W\(100\%\) > * > TR > TD[colspan=""""]:not([rowspan]):nth-child(1):nth-last-child(12) + TD[colspan=""""]:not([rowspan]):nth-child(2):nth-last-child(11) + TD[colspan=""""]:not([rowspan]):nth-child(3):nth-last-child(10) + TD[colspan=""""]:not([rowspan]):nth-child(4):nth-last-child(9) + TD[colspan=""""]:not([rowspan]):nth-child(5):nth-last-child(8) + TD[colspan=""""]:not([rowspan]):nth-child(6):nth-last-child(7) + TD[colspan=""""]:not([rowspan]):nth-child(7):nth-last-child(6) + TD[colspan=""""]:not([rowspan]):nth-child(8):nth-last-child(5) + TD[colspan=""""]:not([rowspan]):nth-child(9):nth-last-child(4) + TD[colspan=""""]:not([rowspan]):nth-child(10):nth-last-child(3)"}, {"Column11", "TABLE.W\(100\%\) > * > TR > TH:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(12) + TH:not([colspan]):not([rowspan]):nth-child(2):nth-last-child(11) + TH:not([colspan]):not([rowspan]):nth-child(3):nth-last-child(10) + TH:not([colspan]):not([rowspan]):nth-child(4):nth-last-child(9) + TH:not([colspan]):not([rowspan]):nth-child(5):nth-last-child(8) + TH:not([colspan]):not([rowspan]):nth-child(6):nth-last-child(7) + TH:not([colspan]):not([rowspan]):nth-child(7):nth-last-child(6) + TH:not([colspan]):not([rowspan]):nth-child(8):nth-last-child(5) + TH:not([colspan]):not([rowspan]):nth-child(9):nth-last-child(4) + TH:not([colspan]):not([rowspan]):nth-child(10):nth-last-child(3) + TH:not([colspan]):not([rowspan]):nth-child(11):nth-last-child(2), TABLE.W\(100\%\) > * > TR > TD[colspan=""""]:not([rowspan]):nth-child(1):nth-last-child(12) + TD[colspan=""""]:not([rowspan]):nth-child(2):nth-last-child(11) + TD[colspan=""""]:not([rowspan]):nth-child(3):nth-last-child(10) + TD[colspan=""""]:not([rowspan]):nth-child(4):nth-last-child(9) + TD[colspan=""""]:not([rowspan]):nth-child(5):nth-last-child(8) + TD[colspan=""""]:not([rowspan]):nth-child(6):nth-last-child(7) + TD[colspan=""""]:not([rowspan]):nth-child(7):nth-last-child(6) + TD[colspan=""""]:not([rowspan]):nth-child(8):nth-last-child(5) + TD[colspan=""""]:not([rowspan]):nth-child(9):nth-last-child(4) + TD[colspan=""""]:not([rowspan]):nth-child(10):nth-last-child(3) + TD[colspan=""""]:not([rowspan]):nth-child(11):nth-last-child(2)"}, {"Column12", "TABLE.W\(100\%\) > * > TR > TH:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(12) + TH:not([colspan]):not([rowspan]):nth-child(2):nth-last-child(11) + TH:not([colspan]):not([rowspan]):nth-child(3):nth-last-child(10) + TH:not([colspan]):not([rowspan]):nth-child(4):nth-last-child(9) + TH:not([colspan]):not([rowspan]):nth-child(5):nth-last-child(8) + TH:not([colspan]):not([rowspan]):nth-child(6):nth-last-child(7) + TH:not([colspan]):not([rowspan]):nth-child(7):nth-last-child(6) + TH:not([colspan]):not([rowspan]):nth-child(8):nth-last-child(5) + TH:not([colspan]):not([rowspan]):nth-child(9):nth-last-child(4) + TH:not([colspan]):not([rowspan]):nth-child(10):nth-last-child(3) + TH:not([colspan]):not([rowspan]):nth-child(11):nth-last-child(2) + TH:not([colspan]):not([rowspan]):nth-child(12):nth-last-child(1), TABLE.W\(100\%\) > * > TR > TD[colspan=""""]:not([rowspan]):nth-child(1):nth-last-child(12) + TD[colspan=""""]:not([rowspan]):nth-child(2):nth-last-child(11) + TD[colspan=""""]:not([rowspan]):nth-child(3):nth-last-child(10) + TD[colspan=""""]:not([rowspan]):nth-child(4):nth-last-child(9) + TD[colspan=""""]:not([rowspan]):nth-child(5):nth-last-child(8) + TD[colspan=""""]:not([rowspan]):nth-child(6):nth-last-child(7) + TD[colspan=""""]:not([rowspan]):nth-child(7):nth-last-child(6) + TD[colspan=""""]:not([rowspan]):nth-child(8):nth-last-child(5) + TD[colspan=""""]:not([rowspan]):nth-child(9):nth-last-child(4) + TD[colspan=""""]:not([rowspan]):nth-child(10):nth-last-child(3) + TD[colspan=""""]:not([rowspan]):nth-child(11):nth-last-child(2) + TD[colspan=""""]:not([rowspan]):nth-child(12):nth-last-child(1)"}}, [RowSelector="TABLE.W\(100\%\) > * > TR"]),
// Set the headers
Result = Table.PromoteHeaders(TableFromHtml, [PromoteAllScalars=true])
in
// Return the batch as a table
Result,
// Call the function above for each page to be loaded
// List.Accumulate is a nice function for this purpose
Combined = List.Accumulate(
{0..10}, // For 9000+ records, this needs to be changed to 0..40 - it might load really slow, basically 40 page loads
#table({}, {}), // Starting with an empty table
(state, current) => state & fnGetTable(current) // Adding each table to the previous one during this loop
),
// Finally change the column types. Again, when Yahoo decides to add new columns or change a column name, then this will fail
Result = Table.TransformColumnTypes(Combined,{{"Symbol", type text}, {"Name", type text}, {"Price (Intraday)", type number}, {"Change", type number}, {"% Change", Percentage.Type}, {"Market Cap", type text}, {"Volume in Currency (Since 0:00 UTC)", type text}, {"Volume in Currency (24Hr)", type text}, {"Total Volume All Currencies (24Hr)", type text}, {"Circulating Supply", type text}, {"52 Week Range", type text}, {"Day Chart", type text}})
in
Result