Mr. B
Mr. B

Reputation: 2787

Targeting a meta tag and its values with XPath in Google Sheets

I'm trying to complete a IMPORTXML function that targets a <meta> tag and it's content= value. I'm not a developer and I know I'm missing something basic, but I can't figure it out. Any help is greatly appreciated.

Partial IMPORTXML Function

I believe this function gets to the level containing the tag I'm trying to pull.

 =IMPORTXML("https://www.officedepot.com/a/products/273646","//div[@id='skuActions']//table//tr[@id='trOneTimeDeliv']/td")

I'm trying to pull the content value of $34.99 out of the tag below.

<meta itemprop="price" content="$34.99" />

It is found in the URL below

https://www.officedepot.com/a/products/273646/Office-Depot-Brand-White-Copy-Paper/

Upvotes: 0

Views: 581

Answers (1)

Tanaike
Tanaike

Reputation: 201358

Although I'm not sure whether this is what you want, how about this? https://www.officedepot.com/a/products/273646/Office-Depot-Brand-White-Copy-Paper/ is in a cell "A1".

Pattern 1 :

=IMPORTXML(A1,"//meta[@itemprop='price'][1]/@content")

enter image description here

Pattern 2 :

=IMPORTXML(A1,"//td[@class='border_bottom'][3]//div[@class='unified_price_row unified_sale_price red_price']//span[@class='price_column right']")

enter image description here

Note :

  • Error sometimes occurs for this URL. It was found that the reason is that the login screen is displayed. At that time, please try again.

If I misunderstand your question, I'm sorry.

Upvotes: 2

Related Questions