【问题标题】:How to extract the price with importxml google sheets xpath如何使用 importxml google sheet xpath 提取价格
【发布时间】:2020-04-06 12:50:14
【问题描述】:

早上好,

我无法使用 importxml 函数提取此页面上的价格: https://www.t-collector.com/reine?prop%5Bcolor%5D=black&product=26&side=front

我需要它来更新我的 Google 商家文件。 我尝试了不同的公式,例如:

=importxml(G2;"//span[@itemprop='price']")
=importxml(G2;"//b[@itemprop='price']/@content")
=importxml(G2;"//b[@itemprop='price'][1]/@content")
=importxml(G2;"//meta[@itemprop='price'][1]/@content")
=importxml("G2";"//span[@itemprop='price']")

但没有任何效果

谢谢 真诚的

【问题讨论】:

  • 请张贴一份样本表,其中包含您尝试过的 3 个不同的公式。
  • 早上好,先生,我尝试了不同的公式,例如: =importxml(G2;"//span[@itemprop='price']") =importxml(G2;"//b[ @itemprop='price']/@content") =importxml(G2;"//b[@itemprop='price'][1]/@content") =importxml(G2;"//meta[@itemprop= 'price'][1]/@content") =importxml("G2";"//span[@itemprop='price']") 但没有任何效果。谢谢

标签: xpath google-sheets


【解决方案1】:

网站使用动态呈现。这里需要硒。但我们可以尝试使用 GoogleSheets。我们使用自定义脚本直接加载 JSON 数据。

使用 GoogleSheets 导入 JSON 数据的脚本(感谢 Paul Gambill):https://gist.github.com/paulgambill/cacd19da95a1421d3164

还有数据:

https://www.t-collector.com/campaigns/C-PGE7F?format=json&store=tcollectorofficiel

我们使用类似 SQL 的公式来只保留价格。结果:

编辑:使用 IMPORTXML 的解决方案:

您可以使用以下公式(用 5 件衬衫测试):

=IMPORTXML(A2;"substring-after(substring-before((//script)[6],'"",""category""'),',""price"":""')")

输出:

编辑 2:修复以欧元为单位提取默认显示价格:

=IMPORTXML(A2;"substring-after(substring-before(//script[starts-with(.,'var campaignObj')],'"",""gbp""'),'""eur"":""')")

输出:

编辑 3:要忽略销售价格,我们可以使用以下一种衬里:

=SI(IMPORTXML(A2;"substring(substring-after(//script[starts-with(.,'var campaignObj')],'""compare_at_prices"":{""eur"":""'),1,1)")=0;IMPORTXML(A2;"substring-after(substring-before(//script[starts-with(.,'var campaignObj')],'"",""gbp""'),'""eur"":""')");IMPORTXML(A2;"substring-before(substring-after(//script[starts-with(.,'var campaignObj')],'""compare_at_prices"":{""eur"":""'),'""')"))

输出:

【讨论】:

  • 您好,非常感谢。那么使用 IMPORTXML 函数是不可能的吗?感谢您的帮助。
  • 不可能?...我们可以试试。检查我更新的答案。
  • 嘿,伙计们,你们太棒了!但是在此示例中:t-collector.com/… 我发现 19.95€ 而不是 29.95€,它不采用显示的默认产品价格,而是另一个变体的价格。感谢您的宝贵帮助,并对我使用翻译的错误深表歉意,我是法国人。亲切的问候
  • 我在这里的源代码中找到了正确的: "ecommtz_total_value": "29.95", "purchase" 但我不知道如何更改您的公式。
  • 它的工作原理如下: =IMPORTXML(G2; "substring-after(substring-before((//script)[6],'"",""purchase""'),', ""ecommtz_total_value"":"""')") 现在的问题是提取的值是美元,因为我猜是谷歌机器人触发了美元而不是我希望的欧元显示。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-28
  • 2019-03-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多