简体   繁体   中英

IMPORTXML Google Sheets for every 2nd node?

I'm having trouble trying to get a value with IMPORTXML in a google spreadsheet...

I am using as xpath:

//*[contains(@class,"price") which returns me smoothly, ALL prices posted on a web page

The problem is that within that same class (and I don't know why, with dynamic ID's:) I have 2 nodes/prices, "Registered Customer Price" and "Non-Customer Price". which is the 2nd. value... and the one I am interested in obtaining.

So, I wanted to apply it like this:

(//*[contains(@class,"price")])[2] and with this, I only get the 2nd price... but of the whole page. (and not the 2nd. price of each and every item!)

I assume it is a "syntax" problem... but no matter how many times I try it, I don't get the expected result!

Can you give me a hand with this? Thanks in advance for any suggestion!

try:

=FILTER(IMPORTXML(
 "http://www.maxiconsumo.com/sucursal_villa_dominico/comestibles/aceites/aceite-girasol.html";
 "//*[contains(@id,'price-including-tax')]"); MOD(ROW(INDIRECT("A1:A"&COUNTA(IMPORTXML(
 "http://www.maxiconsumo.com/sucursal_villa_dominico/comestibles/aceites/aceite-girasol.html";
 "//*[contains(@id,'price-including-tax')]")))); 2)=0)

Just use:

//div[@class='price-box'][2]//span[@id]

Output:

价格

EDIT: With IMPORTFROMWEB:

//h4[.="Precio unitario por unidad"]/following-sibling::span/span[@id]

互联网

EDIT 2: More robust XPath:

//h4[.="Precio unitario por unidad"]/following-sibling::span[@class="price-excluding-tax"][count(following-sibling::*)=0]/span[@id]

使固定

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM