How importxml google sheets Can use * in class substring value [@class='myClassValue–&"*"']? Forexfactory

huangapple go评论87阅读模式
英文:

How importxml google sheets Can use * in class substring value [@class='myClassValue--&"*"']? Forexfactory

问题

我正在尝试一次导入分为3个子类的类中的所有值。

该类被细分为3个“子类”子字符串值,分别附加了"--low"、"--medium"、"--high",如下所示:

<td class="calendar__cell calendar__impact impact calendar__impact calendar__impact--low">
<td class="calendar__cell calendar__impact impact calendar__impact calendar__impact--medium">
<td class="calendar__cell calendar__impact impact calendar__impact calendar__impact--high">

我尝试了每个单独类的有效解决方案:

我的第一个类的Xpath查询成功返回所有"low"标记的标题:

//td[@class='calendar__cell calendar__impact impact calendar__impact calendar__impact--low']//span/@title

我的Google Sheets公式:

=IMPORTXML("https://www.forexfactory.com/calendar?month=jul.2023", A1)

截图:
How importxml google sheets Can use * in class substring value [@class='myClassValue–&"*"']? Forexfactory

我想要做的是一次性获取这3个类的所有元素。

我考虑使用正则表达式的全操作符"*",但不确定如何构造它。

我想到了这个公式,但还没有完全达到目标:

//td[@class='calendar__cell calendar__impact impact calendar__impact calendar__impact--&quot;*&quot;']//span/@title

我发现了一个使用contains函数的有效解决方法:

//tbody//span/@title[contains(.,'Impact')]

但我有兴趣知道如何使用正则表达式的全操作符"*"一次查询这3个类的方法。

我之前测试了受@Tanaike答案启发的其他查询:

//table//span/@title
//tbody//span/@title
//tr//span/@title
//tbody//img/@src
英文:

I'm trying to import all at once the values from a class split in 3 subclasses.

The class was subdivided into 3 'subclasses' substrings values appended "--low", "--medium", "--high" like so:

&lt;td class=&quot;calendar__cell calendar__impact impact calendar__impact calendar__impact--low&quot;&gt;
&lt;td class=&quot;calendar__cell calendar__impact impact calendar__impact calendar__impact--medium&quot;&gt;
&lt;td class=&quot;calendar__cell calendar__impact impact calendar__impact calendar__impact--high&quot;&gt;

I tried the working solution for each separated class below:

My Xpath query for the 1st class which returns all the 'low' tagged titles successfully:

//td[@class=&#39;calendar__cell calendar__impact impact calendar__impact calendar__impact--low&#39;]//span/@title

My google sheets formula:

=IMPORTXML(&quot;https://www.forexfactory.com/calendar?month=jul.2023&quot;,a1)

The screenshot:
How importxml google sheets Can use * in class substring value [@class='myClassValue–&"*"']? Forexfactory

What I want to do is get all elements from those 3 classes all at once.

I though of using a regular expression all operator "*" but I'm not sure how to formulate it.

I thought of this formula but it's not there yet:

//td[@class=&#39;calendar__cell calendar__impact impact calendar__impact calendar__impact--&amp;&quot;*&quot;&#39;]//span/@title

I found this working workaround with contains:

//tbody//span/@title[contains(.,&#39;Impact&#39;)]

But I'm interested in knowing how a regular expression all operator "*" way with the 3 classes queried at once would work.

I previously tested those other queries inspired by @Tanaike
answer

//table//span/@title	
//tbody//span/@title	
//tr//span/@title	
//tbody//img/@src

答案1

得分: 1

如果我理解正确,我担心在这种情况下,像 calendar__impact--* 这样的值可能无法使用。在这种情况下,可以考虑如下使用 containsor

修改后的公式:

在这种情况下,将 URL (https://www.forexfactory.com/calendar?month=jul.2023) 放入单元格 "A1"。

=IMPORTXML(A1,"//td[contains(@class,'calendar__impact--low') or contains(@class,'calendar__impact--medium') or contains(@class,'calendar__impact--high')]//span/@title")

或者

=IMPORTXML(A1,"//td[contains(@class,'low') or contains(@class,'medium') or contains(@class,'high')]//span/@title")

或者,在您的 HTML 中,可能可以使用以下 XPath。

=IMPORTXML(A1,"//td[contains(@class,'calendar__impact--') and not(contains(@class,'holiday'))]//span/@title")

测试:

当使用上述公式时,会获得以下结果。单元格 "A2" 和 "B2" 分别包含第 1 和第 2 个公式。

How importxml google sheets Can use * in class substring value [@class='myClassValue–&"*"']? Forexfactory

英文:

If my understanding is correct, I'm worried that in this case, a
value like calendar__impact--* might not be able to be used. In this case, how about using contains and or as follows?

Modified formula:

In this case, the URL (https://www.forexfactory.com/calendar?month=jul.2023) is put into cell "A1".

=IMPORTXML(A1,&quot;//td[contains(@class,&#39;calendar__impact--low&#39;) or contains(@class,&#39;calendar__impact--medium&#39;) or contains(@class,&#39;calendar__impact--high&#39;)]//span/@title&quot;)

or

=IMPORTXML(A1,&quot;//td[contains(@class,&#39;low&#39;) or contains(@class,&#39;medium&#39;) or contains(@class,&#39;high&#39;)]//span/@title&quot;)

or, in your HTML, the following xpath might be able to be used.

=IMPORTXML(A1,&quot;//td[contains(@class,&#39;calendar__impact--&#39;) and not(contains(@class,&#39;holiday&#39;))]//span/@title&quot;)

Testing:

When the above formula is used, the following result is obtained. The cells "A2" and "B2" have the 1st and 2nd formula, respectively.

How importxml google sheets Can use * in class substring value [@class='myClassValue–&"*"']? Forexfactory

huangapple
  • 本文由 发表于 2023年7月17日 17:53:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76703283.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定