Retrieving image url from webpage using IMPORTXML in Google Sheets - google-sheets

I have this webpage: https://www.loupe360.com/diamond/LG464120206/img
And I am trying to retrieve the jpg url using IMPORTXML in google sheets.
example jpg link: https://nivoda-images.s3.amazonaws.com/aHR0cDovL2RuYS5kaWFtb25kdmlkLmNvbS8/aWQ9NjA0NS00LUNWRC1m/0.jpg
I have seen answers online that //img/#src is supposed to retrieve the url but this does not work on my webpage, I have experimented with many different xpath queries, but still cannot seem to retrieve any data from this webpage and I'm not sure why.

if you know the image url you can do:
=IMAGE("https://nivoda-images.s3.amazonaws.com/aHR0cDovL2RuYS5kaWFtb25kdmlkLmNvbS8/aWQ9NjA0NS00LUNWRC1m/0.jpg")

Related

Error in getting data in Google Sheets from URL

I want to get following data (marked in red) from following website.
Image of data I want to get in google sheet
WEBSITE: https://trendlyne.com/equity/PE/NIFTY50/1887/nifty-50/
I tried using importhtml and importxml functions. But I get errors like "could not fetch URL".
For example I used:
=importxml("https://trendlyne.com/equity/PE/NIFTY50/1887/nifty-50/","/html/body/div[3]/div[1]/div[2]/div[2]/div[1]/div")
I am using xPathFinder google chrome plugin to get xPathQuery.
This method is working for other websites, but not working on this one.
Please help. How can I get the data to my Excel sheet.
I tested the same method with other websites and it works but I get the same error with the website you're trying to get data from.
The error "Could not fetch url" basically means that Google is not able to import the content from this specific website. This site is rejecting Google's request to prevent web scraping, so this means that IMPORT functions will not work in this scenario.

Google Sheet Show Image

I'm currently having trouble displaying an image in Google Sheet. I have a Google Form template in which I'm using the FILE UPLOAD function, and I believe the image will be saved in Google Drive, correct?
The responses on the Google Form will be connected on a Google Sheet. So, using Google Sheets, I created a template in which I use the VLOOKUP function to display specific data. When I use the VLOOKUP for the image, it only displays the URL path. Is it possible for me to show it as the image itself?
Upon researching, it says that I need to use =IMAGE() to show an image. However, it seems that it is not working with the =VLOOKUP function.
This is the formula that I used =IMAGE((VLOOKUP(F2,AppData,2,0))) and it only gave me a blank cell.
SAMPLE SPREADSHEET
When VLOOKUP(F2,AppData,2,0) is the URL like https://drive.google.com/open?id=######, in your situation, how about using the following sample formula?
Sample formula:
=IMAGE("https://drive.google.com/uc?export=download&id="&INDEX(SPLIT(VLOOKUP(F2,AppData,2,0),"="),1,2))
or
=IMAGE("https://drive.google.com/uc?export=download&id="&REGEXEXTRACT(VLOOKUP(F2,AppData,2,0),"id\=(.+)"))
By this, the file ID is retrieved from your URL of https://drive.google.com/open?id=###, and the webContentLink is created.
Result:
When your sample Spreadsheet is used, the following result is obtained.
Note:
This sample supposes that your URL is like https://drive.google.com/open?id=###. If the URL is different, this sample might not be able to be used. Please be careful about this.
This sample also supposes that your image file is publicly sharead. Please be careful this.

Is there any API available for Retrieve images in the cell from a google spreadsheet?

I'm trying to Retrieve images in the cell from a google spreadsheet. I checked this question is already available. and I also referred to this documentation. But, these both are no longer work. Does anyone suggests me API or provides any good documentation link?
Edited:
This is my Google Sheet. I'm trying to retrieve A4 and A5. Which is I uploaded from local machine. I used this API. But It's given me the blank value. Is there any other API available for retrieving this both images?
You will not be able to retrieve images placed using the "Upload" functionality. To retrieve via API, the image should be placed using
=IMAGE("http://your.url").
So upload your image to a content server, get the URL and insert them to the respective cells using =IMAGE formula.
Now if you retrieve the grid data using Spreadsheet.get and locate this specific element in the array, you will get the cell value as =IMAGE("http://your.url"), you can parse this string to retrieve the image URL.
You can get a zip file with the sheet in html format with all the images – using Google API. I belive it will be easy to parse it and to get the image you need.
Get Your API Key, from Google developers Console
Get a File ID of a google spreadsheet with permissions set to "Anyone with the link".
Now you're ready to call the api (with curl or browser window):
https://www.googleapis.com/drive/v3/files/{FILE_ID}/export?mimeType=application%2Fzip&key={YOUR API KEY}
fill in your FILE_ID and API_KEY from google.
works only with "anyone with link" permissions, otherwise you gotta authenticate first. (more here: How to send google-sheet data in an email keeping the formatting( colors) intact from python?)

Can text be scraped from Grammarly to google spreadsheet using IMPORTXML function?

I am trying to get texts from the Grammarly application imported into a Google spreadsheet using the IMPORTXML function. To do so, I follow the required syntax IMPORTXML(URL, xpath_query), but it keeps showing an error that the "imported content is empty".
However, the same steps work fine to import data from other websites, and I am confused what might be the matter with Grammarly. Is it because it does allow data scraping at all, maybe?
Thanks for your help. 1 2 3
not possible because this is behind the login gate. google sheets cant read such data

How to use ImportXML in Google Sheets to pull view count data from a Instagram and IGTV Video? [duplicate]

This question already has answers here:
Scraping data to Google Sheets from a website that uses JavaScript
(2 answers)
Closed last month.
I'm trying to pull the view count from a video on Instagram. This is the video: https://www.instagram.com/p/BxEApSqgNJn/
I have been able to get Youtube and Facebook views, but struggling with Instagram.
I have used the following Formula to pull data from Facebook Video:
=IFERROR(LEFT(IMPORTXML(H28,"//*[#data-tooltip-position='below']"),LEN(IMPORTXML(H28,"//*[#data-tooltip-position='below']"))-5),"0")
H28 is the Link
It should show the views the video has achieved, in this case... 351,271 views as of May 14, 2019.
How about this workaround for retrieving the value? In this workaround, the value is retrieved from the data which is preparing for Javascript. The data is updated when the page is loaded, and retrieved using a xpath, and the value is retrieved using a regular expression. So I used this method. The modified formula is as follows. Please think of this as just one of several answers.
Sample formula:
In this sample formula, https://www.instagram.com/p/BxEApSqgNJn/ is put in the cell "A1".
=REGEXEXTRACT(IMPORTXML(A1,"//script[#type='application/ld+json']"),"userInteractionCount"":""(\d+)")
Retrieve data using the xpath of //script[#type='application/ld+json'] with IMPORTXML().
Retrieve the value using the regular expression of userInteractionCount"":""(\d+) with REGEXEXTRACT().
Result:
References:
IMPORTXML
REGEXEXTRACT
If I misunderstood your question and this was not the result you want, I apologize.
unfortunately, that won't be possible because Instagram is controlled by JavaScript and Google Sheets can't understand/import JS. you can test this simply by disabling JS for a given link and you will see a blank page

Resources