【问题标题】:Query does not filter from two values separated by | in NOT CONTAINS string查询不会过滤由 | 分隔的两个值在不包含字符串
【发布时间】:2021-02-21 00:48:07
【问题描述】:

我使用的是公式:

=ARRAYFORMULA(QUERY(TRIM(IMPORTXML("https://www.livescores.com/","//div[@class='content']//div[contains(@class,'row-gray')]")),"Where not Col1 contains 'Postp|Canc' "))

但是由于某种原因'Postp|Canc' 没有删除包含这些值的行,我做错了什么?

【问题讨论】:

    标签: regex web-scraping google-sheets google-sheets-formula google-query-language


    【解决方案1】:

    | 是一个正则表达式,在查询中只有 matches 是正则表达式属性。使用:

    =ARRAYFORMULA(QUERY(TRIM(IMPORTXML("https://www.livescores.com/",
     "//div[@class='content']//div[contains(@class,'row-gray')]")),
     "where not Col1 matches '.*Postp.*|.*Canc.*'"))
    

    或:

    =ARRAYFORMULA(QUERY(TRIM(IMPORTXML("https://www.livescores.com/",
     "//div[@class='content']//div[contains(@class,'row-gray')]")),
     "where not Col1 contains 'Postp' 
         or not Col1 contains 'Canc'"))
    

    【讨论】:

    • 我正在等待 7 分钟将您的答案标记为解决方案,我只有一个问题。必须使用* 而不是+。我用+ 对其进行了测试,但它没有用,但用* 它有效。非常感谢您的帮助!
    【解决方案2】:

    在这个答案中,我想建议修改 xpath。修改后的xpath如下。

    修改后的xpath:

    //div[@class='content']//div[div[@class='min'][not(contains(text(),'Postp') or contains(text(),'Canc'))]]
    

    修改公式:

    =IMPORTXML("https://www.livescores.com/","//div[@class='content']//div[div[@class='min'][not(contains(text(),'Postp') or contains(text(),'Canc'))]]")
    

    结果:

    参考:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-19
      • 1970-01-01
      • 1970-01-01
      • 2013-01-08
      • 1970-01-01
      • 1970-01-01
      • 2023-04-10
      相关资源
      最近更新 更多