Home > Mobile >  Assitance with ImportXML in google sheets
Assitance with ImportXML in google sheets

Time:06-27

I'm putting together a spreadsheet so I can keep track of items my store has for preorder and making it so it updates when stock levels change. I am trying to get it so my sheet tells me whether the webpage button says pre-order or add to basket. Sometimes this works and then other times it doesn't. Here is the formula I have:

=IMPORTXML("https://www.smythstoys.com/uk/en-gb/video-games-and-tablets/gaming-merchandise/harry-potter-lumos-logo-light/p/209816","//html/body/div[7]/section/div/div/div[2]/div[1]/div[5]/div/div/div/div[2]/form/button")

This particular one seems to return an N/A. Outside of trying to teach myself, I don't know Importxml well or the details for HTML as to why this might or might not work. I was also wondering if it were possible to only retrieve certain bits of text but not all of it. So, I have this:

=IMPORTXML("https://www.smythstoys.com/uk/en-gb/video-games-and-tablets/gaming-merchandise/harry-potter-lumos-logo-light/p/209816","//html/body/div[7]/section/div/div/div[2]/div[1]/div[5]/div/div/div/div[2]/form/div[1]/span[14]/table/tbody/tr/td[2]")

which returns "Out of Stock. Expected Stock August 2022". Is it possible to only retrieve the "August 2022" part of that text? Thank you so much to anyone who can help.

CodePudding user response:

To return the button

=index(importxml(url,"//button[@id='addToCartButton']"),1,1)

To get only the availability date

=regexextract(IMPORTXML(_______________),".*: (.*)")
  • Related