英文:
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)
我想要做的是一次性获取这3个类的所有元素。
我考虑使用正则表达式的全操作符"*
",但不确定如何构造它。
我想到了这个公式,但还没有完全达到目标:
//td[@class='calendar__cell calendar__impact impact calendar__impact calendar__impact--"*"']//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:
<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">
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='calendar__cell calendar__impact impact calendar__impact calendar__impact--low']//span/@title
My google sheets formula:
=IMPORTXML("https://www.forexfactory.com/calendar?month=jul.2023",a1)
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='calendar__cell calendar__impact impact calendar__impact calendar__impact--&"*"']//span/@title
I found this working workaround with contains:
//tbody//span/@title[contains(.,'Impact')]
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--*
这样的值可能无法使用。在这种情况下,可以考虑如下使用 contains
和 or
:
修改后的公式:
在这种情况下,将 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 个公式。
英文:
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,"//td[contains(@class,'calendar__impact--low') or contains(@class,'calendar__impact--medium') or contains(@class,'calendar__impact--high')]//span/@title")
or
=IMPORTXML(A1,"//td[contains(@class,'low') or contains(@class,'medium') or contains(@class,'high')]//span/@title")
or, in your HTML, the following xpath might be able to be used.
=IMPORTXML(A1,"//td[contains(@class,'calendar__impact--') and not(contains(@class,'holiday'))]//span/@title")
Testing:
When the above formula is used, the following result is obtained. The cells "A2" and "B2" have the 1st and 2nd formula, respectively.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论