[Logic app] Download a file from from a website with xpath

Nguyen Thi VIet 31 Reputation points
2022-02-15T07:23:17.817+00:00

Hi, I am creating a logic app to automatically download a file from a website.
However, the problem is the file changes every month like the following picture.
174338-image.png

So I am thinking of using the following xpath to download the file and upload it into sharepoint.
/html/body/div/div/div4/div2/div/ul1/li2/a

I am currently using the following structure.
174259-image.png

174391-image.png

174319-image.png

Can you please show me a way to download the file using xpath. Thank you in advance.

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
2,963 questions
{count} votes

1 answer

Sort by: Most helpful
  1. MayankBargali-MSFT 69,946 Reputation points
    2022-02-17T03:43:18.793+00:00

    @Nguyen Thi VIet Logic app does have expression function and you can refer to this document for more details.
    We do have the XPath function that can help you with the use case but as XPath only accepts the XML string so you need to make sure that you are passing the XML string only.

    If you view the source code of any page then you can see in most of the pages there might be <!doctype html> which will make your string as invalid XML when you will try to parse the string to XML using xml function.

    Therefore you need to make sure that you are passing the string without <!doctype html> and you can use split method to split the string and pass the right value.
    For your reference, I have defined the html body to my string variable and using xml and XPath math I am getting the array value. This is only for reference you can modify it as per your end.

    Once you have the href URL you can leverage http connector to get the content and create the file in sharepoint.

    Expression:

    xpath(xml(variables('html')),'/html/body/a/@href')  
    

    Workflow:
    175261-new.gif

    Output:
    175241-image.png