i want to get the banana price from this URL:
“https://www.amazon.com/Fyffes-Organic-Bananas-Banded-Bunch/dp/B07ZLFKBFD/ref=sr_1_1_f3_wg?almBrandId=QW1hem9uIEZyZXNo&crid=2WD7ME588KWYK&dib=eyJ2IjoiMSJ9.P7wom1EHDuMf2BV6ra8AOUjF1jOZTCDq2xaqIzxd83BxbGuHTBkiHK8gSu0kG5u_ExvNW0zcSgbpM6nNi2Yq6hmCnCIbwF7IN7Up8BT1HI6FquNzrRwvUrXQCUhqGb6xjQ2fyVUvEuL74zz3thTRZaH7AkvcvuUOyQxflDRRYkZsk7SVBvHsNRqsf4wWpIS09T2aOTWfkpnIXniCbf2AR0Z1aU_3RCoyzPtq0vj-lQW1LPYxFw83H__kGpExXd9PgmKg3zhjdFr5xu2nnUp_GI0kMHN22tPU5KO82n1miz4.LU-tnqNz1lR2Biew-xrP9N121gWU7xkY20ruHCvrfXI&dib_tag=se&fpw=alm&keywords=banana&qid=1719590970&s=amazonfresh&sprefix=banana%2Camazonfresh%2C549&sr=1-1&th=1”
when i use the IMPORTXML Function by using the url above and the price XPath
“//*[@id=”corePriceDisplay_desktop_feature_div”]/div[1]/span[1]/span/span[1]”
i get this message “imported content is empty”.
i Understand that the problem is because the banana page already gets the price from a JSON script.
i tried this script on google apps script editor:
function getBananaPrice() {
const url = 'https://www.amazon.com/Fyffes-Organic-Bananas-Banded-Bunch/dp/B07ZLFKBFD/ref=sr_1_1_f3_wg?almBrandId=QW1hem9uIEZyZXNo&crid=2WD7ME588KWYK&dib=eyJ2IjoiMSJ9.P7wom1EHDuMf2BV6ra8AOUjF1jOZTCDq2xaqIzxd83BxbGuHTBkiHK8gSu0kG5u_ExvNW0zcSgbpM6nNi2Yq6hmCnCIbwF7IN7Up8BT1HI6FquNzrRwvUrXQCUhqGb6xjQ2fyVUvEuL74zz3thTRZaH7AkvcvuUOyQxflDRRYkZsk7SVBvHsNRqsf4wWpIS09T2aOTWfkpnIXniCbf2AR0Z1aU_3RCoyzPtq0vj-lQW1LPYxFw83H__kGpExXd9PgmKg3zhjdFr5xu2nnUp_GI0kMHN22tPU5KO82n1miz4.LU-tnqNz1lR2Biew-xrP9N121gWU7xkY20ruHCvrfXI&dib_tag=se&fpw=alm&keywords=banana&qid=1719590970&s=amazonfresh&sprefix=banana%2Camazonfresh%2C549&sr=1-1&th=1';
const response = UrlFetchApp.fetch(url);
const html = response.getContentText();
const priceRegex = /<span id="priceblock_ourprice" class="a-size-medium a-color-price priceBlockBuyingPriceString">($d+.d{2})</span>/;
const match = html.match(priceRegex);
if (match && match[1]) {
return match[1];
} else {
return 'Price not found';
}
}
but no result
how can i import the banana price in the Google sheet?
ma07 news is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.