Forum Discussion
Get data from a web
- 5 years ago
Anonymous , you might want to try a complete procedure like this if you insist on List.Generate().
let GetData = (PagePath as number) => Xml.Tables(Web.Contents("https://gtr.ukri.org:443/gtr/api/funds?p="&Text.From(PagePath)&"&s=100")){[Name="fund"]}[Table], Source = List.Generate( () => [page = 1, Page = GetData(page)], each not (try [Page])[HasError], each [page = [page] + 1, Page = GetData(page)], each [Page] ), Dataset = Table.Combine(Source) in Datasetthe condition to contiue the loop is a bit tricky,
each not (try [Page])[HasError]Here's a detailed reference to the syntax of try statement in M language,
https://bengribaudo.com/blog/2020/01/15/4883/power-query-m-primer-part-15-error-handling
Anonymous , you might want to try a complete procedure like this if you insist on List.Generate().
let
GetData = (PagePath as number) =>
Xml.Tables(Web.Contents("https://gtr.ukri.org:443/gtr/api/funds?p="&Text.From(PagePath)&"&s=100")){[Name="fund"]}[Table],
Source = List.Generate(
() => [page = 1, Page = GetData(page)],
each not (try [Page])[HasError],
each [page = [page] + 1, Page = GetData(page)],
each [Page]
),
Dataset = Table.Combine(Source)
in
Datasetthe condition to contiue the loop is a bit tricky,
each not (try [Page])[HasError]Here's a detailed reference to the syntax of try statement in M language,
https://bengribaudo.com/blog/2020/01/15/4883/power-query-m-primer-part-15-error-handling
Thanks. It worked!
However, I changed the website (bold) to grab data from other API (same website but different APIs depending on what info I want to grab). This also happens with other path. Both give "This table is empty".
If this helps, this is the website https://gtr.ukri.org/resources/api.html, and these the endpoints http://gtr.ukri.org/gtr/api/examples
Thanks.
let
GetData = (PagePath as number) =>
Xml.Tables(Web.Contents("https://gtr.ukri.org:443/gtr/api/projects?p="&Text.From(PagePath)&"&s=100")){[Name="fund"]}[Table],
Source = List.Generate(
() => [page = 1, Page = GetData(page)],
each not (try [Page])[HasError],
each [page = [page] + 1, Page = GetData(page)],
each [Page]
),
Dataset = Table.Combine(Source)
in
Dataset