Web.Page

D

T

The M Code Behind the Power Query M function Web.Page

In order to fully understand and utilize the Web.Page function, it is important to have a working knowledge of the M language, which is the language used by Power Query to perform data transformations. In this article, we will dive into the M code behind the Web.Page function and explore its various components and functionalities.

Understanding the Web.Page Function

The Web.Page function is a built-in function within Power Query that allows users to extract data from web pages. It is a powerful tool that can be used to scrape large amounts of data from a website and transform it into a usable format.

To use the Web.Page function, users must first specify the URL of the web page they wish to extract data from. They can then specify which elements of the page they want to extract, such as tables, lists, or specific HTML tags.

The Web.Page function returns a table containing the extracted data, which can then be further transformed and analyzed within Power Query.

Breaking Down the M Code

The M language is used to write the code that instructs Power Query on how to extract and transform data. Let’s break down the M code behind the Web.Page function to gain a better understanding of how it works.

First, we need to specify the URL of the web page we want to extract data from. This is done using the following code:


let

Source = Web.Page(Web.Contents("https://www.example.com"))

in

Source


In this code, we use the Web.Contents function to retrieve the contents of the web page we want to extract data from. We then pass this content to the Web.Page function, which extracts the desired elements and returns a table.

Next, we can specify which elements we want to extract from the web page. This is done using the following code:


let

Source = Web.Page(Web.Contents("https://www.example.com")),

Table = Source{0}[Tables]{0}

in

Table


In this code, we first retrieve the web page contents using the Web.Contents and Web.Page functions. We then use the curly braces to navigate to the desired element within the table. In this case, we are extracting the first table on the web page.

Finally, we can further transform the extracted data using various Power Query functions and techniques. For example, we can use the Split Column function to split a column containing multiple values into separate columns. We can also use the Filter Rows function to remove unwanted rows from the table.

The Web.Page function is a powerful tool within Power Query that allows users to extract data from web pages directly into a Power Query table. By understanding the M code behind the function, users can gain a deeper understanding of how it works and how to further transform the extracted data.

In this article, we have explored the basics of the Web.Page function and broken down the M code used to extract data from a web page. With this knowledge, users can begin to harness the power of Power Query to extract and transform data from a wide variety of sources.

Power Query and M Training Courses by G Com Solutions (0800 998 9248)

Upcoming Courses

Contact Us

    Subject

    Your Name (required)

    Company/Organisation

    Email (required)

    Telephone

    Training Course(s)

    Your Message

    Upload Example Document(s) (Zip multiple files)