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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
HDave
New Member

Dynamic google news search based on keyword by user

Hi,

 

I am new to Power Bi. I want the user to provide user 2 text inputs (keyword1, keyword2). Basis both, I would want to fetch google news and show the latest news.

 

Below is the code I got from one of the posts

Function :

(symbol)=>

let
Source = Web.BrowserContents("https://news.google.com/search?q="&symbol&"&hl=en-NZ&gl=NZ&ceid=NZ%3Aen"),
#"Extracted Table From Html" = Html.Table(Source, {{"Column1", ".nID9nc .DY5T1d"}, {"Column2", ".nID9nc .xBbh9"}, {"Column3", ".nID9nc .wEwyrc"}, {"Column4", ".nID9nc .WW6dff"}, {"Column5", ".nID9nc .hEsB5d"}, {"Column6", ".nID9nc .gQtGhf"}, {"Column7", ".nID9nc .OGsJDe .DPvwYc"}, {"Column8", ".nID9nc .uG2FLd .DPvwYc"}, {"Column9", ".nID9nc .GB1Zid .DPvwYc"}, {"Column10", ".AZtY5d SPAN"}}, [RowSelector=".nID9nc"]),
#"Changed Type" = Table.TransformColumnTypes(#"Extracted Table From Html",{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}, {"Column4", type text}, {"Column5", type text}, {"Column6", type text}, {"Column7", type text}, {"Column8", type text}, {"Column9", type text}, {"Column10", type text}}),
#"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Column1", "Headline"}, {"Column2", "Detail"}, {"Column3", "Source"}, {"Column4", "Time"}}),
#"Removed Other Columns" = Table.SelectColumns(#"Renamed Columns",{"Headline", "Detail", "Source", "Time"})
in
#"Removed Other Columns"

 

Below is the file extraction:

let
Source = Excel.Workbook(File.Contents("C:\Users\xxx\Downloads\Search File.xlsx"), null, true),
Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
#"Changed Type" = Table.TransformColumnTypes(Sheet1_Sheet,{{"Column1", type text}}),
#"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
#"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Symbol", type text}}),
#"Invoked Custom Function" = Table.AddColumn(#"Changed Type1", "News_google", each News([Symbol])),
#"Expanded News_google" = Table.ExpandTableColumn(#"Invoked Custom Function", "News_google", {"Headline", "Detail", "Source", "Time"}, {"Headline", "Detail", "Source", "Time"})
in
#"Expanded News_google"

 

Regarding,

Hema

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

HI @HDave,

I think you need to get data from the google news API instead of the news pages. The news pages show the result formatted by scripts that get data from source data API.(power bi web connector will block these external scripts and codes from the web page)

Google Developers

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

1 REPLY 1
v-shex-msft
Community Support
Community Support

HI @HDave,

I think you need to get data from the google news API instead of the news pages. The news pages show the result formatted by scripts that get data from source data API.(power bi web connector will block these external scripts and codes from the web page)

Google Developers

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.