Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Johns23
Regular Visitor

Want to Import data table from different sites to my website by using Code

I found following code:

 

let
    Source = Web.Page(Web.Contents("https://www.baseball-reference.com/play-index/batter_vs_pitcher.cgi?batter=arenano01")),
    Data1 = Source{1}[Data],
    #"Changed Type" = Table.TransformColumnTypes(Data1,{{"Name", type text}, {"PA", Int64.Type}, {"AB", Int64.Type}, {"H", Int64.Type}, {"2B", Int64.Type}, {"3B", Int64.Type}, {"HR", Int64.Type}, {"RBI", Int64.Type}, {"BB", Int64.Type}, {"SO", Int64.Type}, {"BA", type number}, {"OBP", type number}, {"SLG", type number}, {"OPS", type number}, {"SH", Int64.Type}, {"SF", Int64.Type}, {"IBB", Int64.Type}, {"HBP", Int64.Type}, {"GDP", Int64.Type}, {"missG", type text}})
in
    #"Changed Type"

Suppose I have around 10 to 20 webpages that are exactly the same in structure, but they contain different data. Is there a way to retrieve this data using a single query and combine the results instead of running 20 separate queries for each webpage?

Can Power BI handle this task, or do I need to rely on my VBA skills to import all the data into Excel?

1 ACCEPTED SOLUTION
AlienSx
Super User
Super User

Hi, @Johns23 all you need is a list of URLs. Then List.Transform and Table.Combine. Smth like this:

let 
  url_list = {"url01", "url02", "url03"},
  combined_results = Table.Combine(List.Transform(url_list, each Web.Page(Web.Contents(_))){1}[Data])
in combined_results

you may create a table with links in Excel => get data from table to have the table in PQ and refer to table column to get a list. Or you may simply make the same transformation to your table (instead of list) but using Table.TransformColumns function. I hope you get the idea. 

View solution in original post

2 REPLIES 2
AlienSx
Super User
Super User

Hi, @Johns23 all you need is a list of URLs. Then List.Transform and Table.Combine. Smth like this:

let 
  url_list = {"url01", "url02", "url03"},
  combined_results = Table.Combine(List.Transform(url_list, each Web.Page(Web.Contents(_))){1}[Data])
in combined_results

you may create a table with links in Excel => get data from table to have the table in PQ and refer to table column to get a list. Or you may simply make the same transformation to your table (instead of list) but using Table.TransformColumns function. I hope you get the idea. 

Thank you, for solution

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.