Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
PbiCeo
Helper II
Helper II

How to specify a table where a user can get link URL with Power Query

Hello everyone,

 

I use web connector to get some tables on a site for example (https://www.wsj.com/news/types/the-americas). I want to get link URLs and titles as well (hopefully Column1 titles, Column2 their links).

 

Column1

AMLO’s ‘Hugs’ Won’t End Mexican Mayhem
Leahy’s Yankee Imperialism
Bolton’s Warmed-Over Venezuelan Dish
Cuban Medical Brigades to Mexico
The Culture Wars and the Street Wars
Will Canada Send Oil and Gas Packing?
Lockdown Puts Brazilian Lives at Risk
How Cuba’s Spies Keep Winning
Brazil Doubles Down on Reform
El Salvador’s President Is No Friend of the U.S.
AMLO Tries to Capitalize on Coronavirus
Audit the WHO’s Pan American Arm
No Gasoline in Venezuela
AMLO Defies Medicine and Economics
Repression in the Time of Coronavirus
Economic Flu Stalks Latin America
When Bernie Sanders Met Cuba’s American Hostage
Bernie Rewrites Cuban History
Mexico Slides Toward One-Man Rule
Trump’s Pitch to Puerto Rican Voters

I tried the below Power Query but cound not specify the right table even through recommended table on PBI desktop.

------

let
Source =
Web.BrowserContents("https://www.wsj.com/news/types/the-americas"),
Links =
Html.Table(
Source,
{{
"Link",
"a[href^=""http""]",
each [Attributes][href]}})
in
Links

------
https://blog.crossjoin.co.uk/2018/08/30/power-bi-extract-urls-web-page/

Is there any way to specify the right table?
Vladi

1 ACCEPTED SOLUTION
dax
Community Support
Community Support

Hi @PbiCeo , 

You could try below M code 

let
    Source = 
     Web.BrowserContents("https://www.wsj.com/news/types/the-americas"),
    Links = 
     Html.Table(
      Source, 
      {{
       "Link", 
       "a[href^=""https://www.wsj.com/articles/""]", 
       each [Attributes][href]}}),
    #"Duplicated Column" = Table.DuplicateColumn(Links, "Link", "Link - Copy"),
    #"Replaced Value" = Table.ReplaceValue(#"Duplicated Column","https://www.wsj.com/articles/","",Replacer.ReplaceText,{"Link - Copy"}),
    #"Extracted Text Before Delimiter" = Table.TransformColumns(#"Replaced Value", {{"Link - Copy", each Text.BeforeDelimiter(_, "-", {0, RelativePosition.FromEnd}), type text}}),
    #"Renamed Columns" = Table.RenameColumns(#"Extracted Text Before Delimiter",{{"Link - Copy", "name"}}),
    #"Capitalized Each Word" = Table.TransformColumns(#"Renamed Columns",{{"name", Text.Proper, type text}})
in
    #"Capitalized Each Word"

Best Regards,
Zoe Zhi

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

View solution in original post

1 REPLY 1
dax
Community Support
Community Support

Hi @PbiCeo , 

You could try below M code 

let
    Source = 
     Web.BrowserContents("https://www.wsj.com/news/types/the-americas"),
    Links = 
     Html.Table(
      Source, 
      {{
       "Link", 
       "a[href^=""https://www.wsj.com/articles/""]", 
       each [Attributes][href]}}),
    #"Duplicated Column" = Table.DuplicateColumn(Links, "Link", "Link - Copy"),
    #"Replaced Value" = Table.ReplaceValue(#"Duplicated Column","https://www.wsj.com/articles/","",Replacer.ReplaceText,{"Link - Copy"}),
    #"Extracted Text Before Delimiter" = Table.TransformColumns(#"Replaced Value", {{"Link - Copy", each Text.BeforeDelimiter(_, "-", {0, RelativePosition.FromEnd}), type text}}),
    #"Renamed Columns" = Table.RenameColumns(#"Extracted Text Before Delimiter",{{"Link - Copy", "name"}}),
    #"Capitalized Each Word" = Table.TransformColumns(#"Renamed Columns",{{"name", Text.Proper, type text}})
in
    #"Capitalized Each Word"

Best Regards,
Zoe Zhi

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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors