0

I was wondering whether it is possible to extract the link details from a cell when hovering the mouse over it?

For example the instagram followers of Kim Kardashian account as follows:

enter image description here

1 Answer 1

1

I do not think you could obtain values from the social media preview of the link, directly via the popover, easily.

The content seen in the social media preview are embedded under the meta tags within the HTML of the relevant webpage and the content can be scrapped by parsing the relevant HTTP response.

Solution 1

You could use Google Sheet's IMPORTXML() and the suitable XPath, which helps in pointing to the data you want. The below is to be used as a cell value.

=IMPORTXML([Relevant cell id; Example: A1],"/html/head/meta[14]/@content]")

However, this does produces an error: "Could not fetch url", on my end, despite using the valid example URL that you gave.

Solution 2

You could leverage on a Google sheet bounded Google Apps Script with the below code and suitable constraints:

function fetchContent(url) {
    const htmlResponse = UrlFetchApp.fetch(url).getContentText();
    return Parser.data(htmlResponse).from("<meta content=\"").to("\"").build(); }

The relevant cell value to be:

=fetchContent([Relevant cell id])

However, when using the example URL, this solution also causes an error:"Exception: Request failed for https://www.instagram.com... returned code 429 ..", alluding that there has been too many HTTP request made to Instagram from the relevant IP address. See this SO Q&A regarding IP addresses associated with App script's UrlFetchApp()and this SO Q&A regarding Instagram blocking IP addresses.

In theory, the above solutions should work for other websites which do not block IP addresses.

Obtaining specific parts of the content via Google Apps script should be straightforward, but for within Google Sheets you could check out this SO Q&A and the related ones.

If you need to obtain data specifically from Instagram, you could check out Instagram's Graph API.

1
  • 1
    thanks for the answer! It still seems weird to me that it is not possible to extract those elements somehow... Commented May 4, 2022 at 10:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.