Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Power Query - HTML

Hi,  I want to extract the text from html retaining the formatting. I used html.table function but it is not giving the desired output input: <ol style="list-style-image: none; list-style-type: de...
  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi Anonymous ,

     

    1. Click the column--> Split by Custom delimiter "<li>"

    2. Select the two new columns--> Extract between delimiters:

    3. Then you could remove the original column and Transpose the columns.

     

    Here is the whole M syntax:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wiik1MDBOzs9RKC6pzEm1jVHKySwu0QVzdDNzE9NTrRTy8vNSrRWQxEsqC4DCKanJQAU51jEQM1IhJuVkQnghqcUlCkmVCrlQcX2YBKayzLx0rGr083MgXKXYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
        #"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type", "Column1", Splitter.SplitTextByDelimiter("<li>", QuoteStyle.Csv), {"Column1.1", "Column1.2", "Column1.3"}),
        #"Extracted Text Before Delimiter" = Table.TransformColumns(#"Split Column by Delimiter", {{"Column1.2", each Text.BeforeDelimiter(_, "</li>"), type text}, {"Column1.3", each Text.BeforeDelimiter(_, "</li>"), type text}}),
        #"Removed Columns" = Table.RemoveColumns(#"Extracted Text Before Delimiter",{"Column1.1"}),
        #"Transposed Table" = Table.Transpose(#"Removed Columns")
    in
        #"Transposed Table"

     

    Final output:

     

    Best Regards,
    Eyelyn Qin
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.