Forum Discussion

Omid_Motamedise's avatar
Omid_Motamedise
Icon for Super User rankSuper User
1 year ago

Improve time of load from web

To load data from this https://companiesmarketcap.com/aud/, I use the following formula but it takes to much time to load all the data, is there any way to make it more efficient?

 

let
Source = Table.Combine(List.Generate(()=>[page=1, t=LoadTopCompanies("https://companiesmarketcap.com/aud/page/" & Text.From(page)&"/")], each not Table.IsEmpty(_[t]) , each [page=_[page]+1, t=(LoadTopCompanies("https://companiesmarketcap.com/aud/page/" & Text.From(page)&"/"))] ,each _[t]))
in
Source

 

 

 

 

 

which LoadTopCompanies is a custom function as follow

(URL)=>

let
Source = Web.BrowserContents(URL),
#"Extracted Table From Html" = Html.Table(Source, {{"Column1", ".d-none"}, {"Column2", ".d-none + *"}, {"Column3", ".rh-sm"}, {"Column4", ".rh-sm + *"}, {"Column5", ".company-name"}, {"Column6", ".company-code"}, {"Column7", ".rank"}, {"Column8", ".td-right:nth-child(5)"}, {"Column9", ".p-0 + *"}, {"Column10", ".currency-symbol-left"}}, [RowSelector=".d-none"]),
#"Promoted Headers" = Table.PromoteHeaders(#"Extracted Table From Html", [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"#", type text}, {"Name", type text}, {"1d", type text}, {"Price (30 days)", type text}, {"Column5", type text}, {"Column6", type text}, {"Column7", Int64.Type}, {"Column8", Currency.Type}, {"Column9", type text}, {"Column10", type text}}),
#"Removed Bottom Rows" = Table.RemoveLastN(#"Changed Type",1)
in
#"Removed Bottom Rows"

4 Replies

    • Omid_Motamedise's avatar
      Omid_Motamedise
      Icon for Super User rankSuper User

      Thanks for the response, yes I can by I need to refresh it on a weekly period. 

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Omid_Motamedise ,

     

    If the data doesn't change often, you can implement incremental loading to get only new or updated data. But this does not seem to be the case here.

    In addition to Tom's opinion, you can load multiple pages in parallel. This can significantly reduce the total loading time.

    Here's the modified codes:

    let
        // Define a function to load a single page
        LoadPage = (page as number) as table =>
            let
                URL = "https://companiesmarketcap.com/aud/page/" & Text.From(page) & "/",
                Source = Web.BrowserContents(URL),
                ExtractedTable = Html.Table(Source, {{"Column1", ".d-none"}, {"Column2", ".d-none + *"}, {"Column3", ".rh-sm"}, {"Column4", ".rh-sm + *"}, {"Column5", ".company-name"}, {"Column6", ".company-code"}, {"Column7", ".rank"}, {"Column8", ".td-right:nth-child(5)"}, {"Column9", ".p-0 + *"}, {"Column10", ".currency-symbol-left"}}, [RowSelector=".d-none"]),
                PromotedHeaders = Table.PromoteHeaders(ExtractedTable, [PromoteAllScalars=true]),
                // Inspect the column names
                ColumnNames = Table.ColumnNames(PromotedHeaders),
                // Adjust column names if necessary
                RenamedColumns = Table.RenameColumns(PromotedHeaders, List.Zip({ColumnNames, {"#", "Name", "1d", "Price (30 days)", "Column5", "Column6", "Column7", "Column8", "Column9", "Column10"}})),
                ChangedType = Table.TransformColumnTypes(RenamedColumns,{{"#", type text}, {"Name", type text}, {"1d", type text}, {"Price (30 days)", type text}, {"Column5", type text}, {"Column6", type text}, {"Column7", Int64.Type}, {"Column8", Currency.Type}, {"Column9", type text}, {"Column10", type text}}),
                RemovedBottomRows = Table.RemoveLastN(ChangedType, 1)
            in
                RemovedBottomRows,
    
        // Generate a list of page numbers
        PageNumbers = {1..10}, // Adjust the range as needed
    
        // Load all pages in parallel
        LoadAllPages = List.Transform(PageNumbers, each LoadPage(_)),
    
        // Combine all tables into one
        CombinedTable = Table.Combine(LoadAllPages)
    in
        CombinedTable

    Best Regards,

    Stephen Tao

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

     

    • Omid_Motamedise's avatar
      Omid_Motamedise
      Icon for Super User rankSuper User

      Thanks for the reply, but it does not impacted the loading result. You have just load the first 10 pages and if you use PageNumbers = {1..101}, the execution time is the same