1

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)

The screenshot: enter image description here

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
Lod
  • 657
  • 1
  • 9
  • 30
  • 1
    Although I'm not sure whether I could correctly understand your expected result, I proposed an answer. Please confirm it. If I misunderstood your expected result and that was not useful, I apologize. – Tanaike Jul 17 '23 at 12:44
  • Your answer is perfect as always. Be well! – Lod Jul 17 '23 at 16:32

1 Answers1

1

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.

enter image description here

Tanaike
  • 181,128
  • 11
  • 97
  • 165
  • Thanks a lot @Tanaike! Wow, I just learned through your example we can directly probe the class value and treat it as parsable text as any other tags value. I assumed before that only tags with actual "text" value like "title" could be parsed for string search. Appreciate it! Many thanks again. Be well! – Lod Jul 17 '23 at 16:31
  • Great, I overlooked the 'Non-Economic' one. Here's the fix from the 1st solution adapted from your very nice examples: `//tbody//span/@title[contains(.,'Impact') or contains(.,'Non-Economic')]` – Lod Jul 17 '23 at 16:49
  • 1
    @Lod Welcome. Thank you for letting me know. I'm glad your issue was resolved. If your question was solved, please push an accept button. Other people who have the same issue with you can also base your question as a question which can be solved. If you don't find the button, feel free to tell me. https://stackoverflow.com/help/accepted-answer – Tanaike Jul 18 '23 at 01:00
  • Thanks again sorry for the accept button, I was distracted by the Non-Economic remaining detail and forgot to check it yersterday. – Lod Jul 18 '23 at 09:58
  • 1
    @Lod Thank you for your response. I'm glad your issue was resolved. Thank you, too. – Tanaike Jul 18 '23 at 12:17
  • Why is it not working on this one? Google Sheets Output: https://i.imgur.com/MkW2lLB.png Xpath working: https://i.imgur.com/kf3cGqM.png `//td[1]//span[contains(@class,'cluster')]//span/@thesw` Xpath not working: https://i.imgur.com/rh1XMFb.png `//td[1]//span[contains(@class,'cluster')]//span/@thesw` Any fix suggestion? thanks a lot! The URL: https://www.onelook.com/thesaurus/?s=active – Lod Aug 18 '23 at 17:10
  • I also tested this following the sibling approach `//td[1]/span[2]/@thesw` from this post https://stackoverflow.com/a/11657408/10789707 Working Xpath https://i.imgur.com/QPu2YQU.png Not Working Google Sheets https://i.imgur.com/wxU1HaA.png – Lod Aug 18 '23 at 17:36
  • From this https://stackoverflow.com/a/11657408/10789707 I could retrive the text using `//td[1]//span[contains(@class,'cluster')]/text()[1]` but still doesn work in Google Sheet. Any workaround? Thanks again. – Lod Aug 18 '23 at 17:58
  • 1
    @Lod About your new questions, I have to apologize for my poor English skill. Unfortunately, I cannot understand your new questions. But, I would like to support you. So, can you post it as a new question by including more information? By this, it will help users including me think of your new question. If you can cooperate to resolve your new question, I'm glad. Can you cooperate to do it? – Tanaike Aug 19 '23 at 00:10
  • thanks for the reply. I found this answer https://stackoverflow.com/a/74245749/10789707 and I think my question has many duplicates so I'm not sure I should post a new one. I see the url https://www.onelook.com/thesaurus/?s=active loads jquery and Bubbling: https://i.imgur.com/zgnoSgz.png . – Lod Aug 19 '23 at 11:59
  • I checked for json using this method: https://stackoverflow.com/a/58920065/10789707 but could not find the data (only this json https://www.onelook.com/thesaurus_manifest.json is available). Is it possible to use importxml? If not, maybe google apps script? Should I post a new question for Apps Script instead? Many thanks for your remarks. – Lod Aug 19 '23 at 11:59
  • 1
    @Lod Thank you for replying. About `Should I post a new question for Apps Script instead?`, I think that it's yes. I would like to try to understand your new question from your posted question including more information. – Tanaike Aug 19 '23 at 12:04
  • All right I just did here: https://stackoverflow.com/questions/76935145/jquery-and-bubbling-loaded-page-imported-content-empty-google-sheet-importxml thanks again! – Lod Aug 19 '23 at 12:39