Retrieve Metadata of a Web Page using Power Automate Desktop
Retrieve Metadata of a Web Page using Power Automate Desktop
This Power Automate Desktop flow allows the user to enter a website URL and automatically retrieves important metadata such as the page title, meta keywords, description, and the full HTML source. It uses browser automation to open the page, extract information, and optionally save the source code to a file.
Step-by-step Explanation
-
Ask the user for a website URL
The flow begins with an input dialog that prompts the user to enter the website address. The entered URL is stored in the variableURL. If the user clicks Cancel, the remaining steps do not execute. -
Open the website in Microsoft Edge
If the user clicks OK, the flow launches Edge and opens the provided webpage. The browser window is maximized, and a retry mechanism is added in case the page fails to load on the first attempt.
⚠️ The Power Automate browser extension must be installed for this to work. -
Retrieve the title of the webpage
The action GetDetailsOfWebPage → Title extracts the webpage title and displays it in a message box to the user. -
Retrieve the meta keywords
The flow then extracts the webpage’s meta keywords.- If keywords exist → Show them in a message box
- If keywords do not exist → Inform the user that no keywords are specified
-
Retrieve the meta description
The description is extracted next. Similar to keywords:- If description exists → Display it
- If not → Show a “No description” message
-
Ask if the user wants to save the HTML source
A Yes/No dialog asks whether to save the page’s HTML source locally.- If the user selects No, the flow skips to the last step.
- If the user selects Yes, a file selection dialog appears:
pagecode.txt). -
Save the HTML source to a local file
If a file is selected and the user did not press Cancel:- The entire HTML source is extracted using DetailsType: Source.
- The content is written into the chosen file.
- If the file already exists, it will be overwritten.
-
Close the browser
After all metadata has been retrieved, the flow safely closes the Edge browser window.
Full Power Automate Desktop Code
# The 'Display input dialog' action prompts you to enter the address of the website you want to retrieve the metadata from.
Display.InputDialog Title: $'''Get metadata of a web page''' Message: $'''Please provide the web page address that you want to examine:''' DefaultValue: $'''https://mspowerplatformtips.blogspot.com/''' InputType: Display.InputType.SingleLine IsTopMost: True UserInput=> URL ButtonPressed=> ButtonPressed
# The following 'If' action checks whether the 'Cancel' button was pressed.
IF ButtonPressed <> $'''Cancel''' THEN
/# Launch the webpage in Edge and retrieve metadata.
Please note that the Power Automate browser extension is required for this flow to work.#/
WebAutomation.LaunchEdge.LaunchEdge Url: URL WindowState: WebAutomation.BrowserWindowState.Maximized ClearCache: False ClearCookies: False Timeout: 60 BrowserInstance=> Browser
ON ERROR REPEAT 1 TIMES WAIT 2
END
WebAutomation.GetDetailsOfWebPage BrowserInstance: Browser DetailsType: WebAutomation.DetailsType.Title Details=> WebPageTitle
Display.ShowMessageDialog.ShowMessage Title: $'''Get metadata of a webpage.''' Message: $'''The title of the given web page is:
%WebPageTitle%'''
WebAutomation.GetDetailsOfWebPage BrowserInstance: Browser DetailsType: WebAutomation.DetailsType.MetaKeywords Details=> WebPageKeywords
IF IsNotEmpty(WebPageKeywords) THEN
Display.ShowMessageDialog.ShowMessage Title: $'''Get metadata of a webpage.''' Message: $'''The keywords specified for the given web page are:
%WebPageKeywords%'''
ELSE
Display.ShowMessageDialog.ShowMessage Title: $'''Get metadata of a webpage.''' Message: $'''No keywords specified for the web page:
%URL%'''
END
WebAutomation.GetDetailsOfWebPage BrowserInstance: Browser DetailsType: WebAutomation.DetailsType.Description Details=> WebPageDescription
IF IsNotEmpty(WebPageDescription) THEN
Display.ShowMessageDialog.ShowMessage Title: $'''Get metadata of a webpage.''' Message: $'''The description for the given web page is:
%WebPageDescription%'''
ELSE
Display.ShowMessageDialog.ShowMessage Title: $'''Get metadata of a webpage.''' Message: $'''No description specified for the web page:
%URL%'''
END
Display.ShowMessageDialog.ShowMessage Title: $'''Do you want to save HTML source? ''' Message: $'''Do you want to save the HTML source of the given webpage locally?
Web page URL: %URL%''' Buttons: Display.Buttons.YesNo ButtonPressed=> SaveSourceButton
IF SaveSourceButton = $'''Yes''' THEN
Display.SelectFileDialog.SelectFile Title: $'''Select a text file to save HTML source into or provide a new name''' FileFilter: $'''*.txt''' CheckIfFileExists: False SelectedFile=> SelectedFile ButtonPressed=> FileSelectedButtonPressed
IF FileSelectedButtonPressed <> $'''Cancel''' THEN
WebAutomation.GetDetailsOfWebPage BrowserInstance: Browser DetailsType: WebAutomation.DetailsType.Source Details=> WebPageSource
File.WriteText File: SelectedFile TextToWrite: WebPageSource AppendNewLine: True IfFileExists: File.IfFileExists.Overwrite Encoding: File.FileEncoding.Unicode
END
END
WebAutomation.CloseWebBrowser BrowserInstance: Browser
END
Comments
Post a Comment