Google Sheets ImportXML - 如果单元格已填充则插入动态查询

Google Sheets ImportXML - Insert dynamic query if cell is filled

我正在使用 Google 表格作为 YouTube 视频的抓取工具。我想让 sheet 更加动态,但它似乎不起作用。

比如我想写"How to get my baby to sleep"作为搜索查询,所以我会把这个查询写到H6中。如果现在填充H6,我想将这个查询动态插入到importXML函数中。

这是我已经拥有的,但我无法让它发挥作用。

=ARRAYFORMULA("https://www.youtube.com"&QUERY(QUERY(UNIQUE(
 IMPORTXML("https://www.youtube.com/results?search_query=**{{dynamicInsertion}}**","//a/@href")),
 "where Col1 contains '/watch?v='"),"limit 50"))

尝试:

=ARRAYFORMULA("https://www.youtube.com/"&QUERY(IMPORTXML(
 "https://www.youtube.com/results?search_query="&H6, "//a/@href"), 
 "where Col1 matches '/channel.+|/watch.+|/user.+|/results.+' 
  order by Col1 desc"))


更新:

=ARRAYFORMULA("https://www.youtube.com/"&QUERY(UNIQUE(IMPORTXML(
 "https://www.youtube.com/results?search_query="&H6, "//a/@href")), 
 "where Col1 matches '/channel.+|/watch.+|/user.+|/results.+' 
  order by Col1 desc limit 50"))

要爬过无限滚动的第一页,请使用:

=QUERY(UNIQUE(QUERY({
 IMPORTXML("https://www.ecosia.org/videos?q="    &SUBSTITUTE(A1, " ", "+"), "//a/@href");
 IMPORTXML("https://www.ecosia.org/videos?p=1&q="&SUBSTITUTE(A1, " ", "+"), "//a/@href");
 IMPORTXML("https://www.ecosia.org/videos?p=2&q="&SUBSTITUTE(A1, " ", "+"), "//a/@href");
 IMPORTXML("https://www.ecosia.org/videos?p=3&q="&SUBSTITUTE(A1, " ", "+"), "//a/@href");
 IMPORTXML("https://www.ecosia.org/videos?p=4&q="&SUBSTITUTE(A1, " ", "+"), "//a/@href");
 IMPORTXML("https://www.ecosia.org/videos?p=5&q="&SUBSTITUTE(A1, " ", "+"), "//a/@href");
 IMPORTXML("https://www.ecosia.org/videos?p=6&q="&SUBSTITUTE(A1, " ", "+"), "//a/@href");
 IMPORTXML("https://www.ecosia.org/videos?p=7&q="&SUBSTITUTE(A1, " ", "+"), "//a/@href");
 IMPORTXML("https://www.ecosia.org/videos?p=8&q="&SUBSTITUTE(A1, " ", "+"), "//a/@href");
 IMPORTXML("https://www.ecosia.org/videos?p=9&q="&SUBSTITUTE(A1, " ", "+"), "//a/@href")}, 
 "where Col1 contains 'watch'")), "limit 50", 0)