Power Query Get Data from Web by Example

Mynda Treacy

May 14, 2019

,

Getting data from the web is possible with Power Query in both Excel and Power BI. However, Excel is a little behind in Power Query features, therefore in this post I’m going to show you a new feature available in Power BI Desktop using Power Query to get data from the web by example.

In time we should also see this feature available in Power Query for Excel.

Getting data using ‘Web by Example’ is super handy for data on web pages that aren’t structured in HTML tables, or where the structure is messy, like this book catalogue site, WorldCat:

WorldCat

From this site I want to extract a list of books by, or about author H J Eysenck. The website allows me to enter a search term that filters the data. You can see in the image above it has returned 21,610 results with the first page showing just 10.

Here is the URL if you want to take a look at the page: https://www.worldcat.org/search?q=Eysenck&fq=&dblist=638&start=1&qt=previous_page

The first challenge is getting the following data from the web page:

  • Book Title
  • Author
  • Type
  • Publisher

It’s a challenge because the data on the page is not formatted in a proper HTML table that Power Query can easily find.

Download Power BI Desktop File

Enter your email address below to download the sample workbook.

By submitting your email address you agree that we can email you our Excel newsletter.

Power Query Get Data from Web by Example

Step 1: Connect to the web page

Let’s start in Power BI Desktop -  Home tab > Get Data > Web:

Power Query Get Data from Web by Example

Step 2: Enter the URL

At the ‘From Web’ dialog box, enter the web page URL:

From Web

Tip: At the privacy setting choose ‘Anonymous’.

Step 3: Provide Examples

At the Navigator dialog box select ‘Add table using examples’:

Add table using examples

Then in the bottom half of the window enter in the column labels you want and provide examples until Power Query detects the pattern:

pbi data from web

Step 4: Edit or Load

The navigator dialog box will now have a Custom Table and you can click ‘Load’ if you’re ready to load it to your model, or ‘Edit’ to perform further transformations to the data in the Power Query editor:

edit or load

The result is a table containing the columns you specified:

custom table

I know what you’re thinking…and no, you can’t copy the M code from the Advanced Editor in Power BI Desktop and paste it into Excel because Excel doesn’t yet recognise the functions Web.BrowserContents and Html.Table. Excel’s Power Query typically sees updates a few months after they are ‘generally available’ in Power BI Desktop.

The Second Challenge – Getting Data from Multiple Web Pages

Remember the first web page only returned 10 results. There were a further 21,600 results available, spread over a further 2,160 pages! In the next tutorial here we’ll look at how we can automate pagination to get all results.

Learn Power Query

If you’d like to learn more of Power Query’s wonders, please consider my Power Query Course. Or check out what Power BI has to offer, in my Power BI Course.

AUTHOR Mynda Treacy Co-Founder / Owner at My Online Training Hub

CIMA qualified Accountant with over 25 years experience in roles such as Global IT Financial Controller for investment banking firms Barclays Capital and NatWest Markets.

Mynda has been awarded Microsoft MVP status every year since 2014 for her expertise and contributions to educating people about Microsoft Excel.

Mynda teaches several courses here at MOTH including Excel Expert, Excel Dashboards, Power BI, Power Query and Power Pivot.

25 thoughts on “Power Query Get Data from Web by Example”

  1. HI Mynda, do you have any advice on how I might Add A Tabe Using Examples from a page like this one so that I can use Power Query to establish parcel delivery status on a courier service traching site?
    https://www.nzpost.co.nz/tools/tracking/item/2425345222547011AKL013AS

    Also, if I had a list of tracking references, how might Power Query work its way down the list, returning a status result for each one?

    Thanks always for the blog, the site – everything,
    Matthew

    Reply
    • Hi Matthew,

      Getting data from the web using examples is currently only available in Power BI. I tested the link and it works well to extract the tracking history. In my Power Query course I cover how to scrape data from multiple web pages based on a list of values, in your case it would be tracking IDs.

      Mynda

      Reply
  2. Can Powerbi extract data from webpages that use Powerbi to display their data. Currently I cant find anything on that topi. I have tried to do it and it wont display the data generated by Powerbi.

    Reply
  3. Thanks Mynda. Actually, with the new “suggested tables” feature currently in preview, you can now get all of this information automatically without having to give examples. Though the suggested tables do contain some extra columns that you may want to filter out.

    Reply
  4. Hi Mynda,

    Thanks for your valuable information. However, I still got problems to add Html.Table function onto “Add table using examples”. Could you please implement that function into your pbix file? I would highly appreciated.

    Best regards,

    Julian

    Reply
  5. Dear Mynda,
    why my excel doesn’t show the “Add table using example” button?
    what should i do?
    Regards,
    Chandra

    Reply
  6. Awesome! I can’t wait for part 2. My big challenge is getting data from a website with login credentials. Will you be addressing that issue? Pretty please!

    Reply
    • Thanks, Kathi! When connecting to a web page requiring a login choose ‘Basic’ authentication and you’ll be able to enter your username and password. That said, there seems to be a bug with this at the moment so it may be hit and miss.

      Reply

Leave a Comment

Current ye@r *