I have a Google Spreadsheet where I have the following information on specific cells in the sheet:
http://www.google.com.co/search?q=NASA+watching+now%3A+site%3Awww.youtube.com
=IMPORTXML(B1,"//title")
Here is the link of the Google spreadsheet - if you want to test from your side.
And here is the Google Spreadsheet I'm working on - which, I want to get the specific data:
h3
HTML tag of the result item).<a>
HTML tag of the result item)See screenshot with the data to get using IMPORTXML
:
The previous code returns the title
of the given URL - in this case, the URL stored in the B1 cell.
It was working without problems (since 12/02/2022 - dd/MM/yyyy) until today (13/02/2022 - dd/mm/yyyy).
I checked the Chrome console "F12 Developer tools" and I get this error:
This document requires 'TrustedScript' assignment.
injectIntoContentWindow @ VM364:27
By clicking the @ VM364:27 line, the following code is shown:
function injectIntoContentWindow(contentWindow)
{
if (contentWindow && !injectedFramesHas(contentWindow))
{
injectedFramesAdd(contentWindow);
try
{
contentWindow[eventName] = checkRequest;
contentWindow.eval( /* ERROR with and (X) is shown here. */
"(" + injectedToString() + ")('" + eventName + "', true);"
);
delete contentWindow[eventName];
}
catch (e) {}
}
}
Searching on the internet, I barely could get the causes of this error:
I've tried:
This document requires 'TrustedScriptURL' assignment
message shows.Another possible cause I consider is maybe my IP was blacklisted or blocked, but, I'm not sure.
My browser information:
Is there any way to solve this error in Google Sheets?
PS: I'm interested in know the workaround using google sheets and/or custom scripts - via script editor/Apps Script. The use of IMPORTXML
function is not mandatory - I find curious that it was working and then today, not anymore.
TL;DR: This document requires 'TrustedScript' assignment
error is not the root cause of the delay of the IMPORTXML
function - probably there is other cause(s) (outside of the developer's handling), but, after all, the code works - see working google spreadsheet - just, wait until the results are shown or use another way to web-scrapping the desired data.
Since the This document requires 'TrustedScript' assignment
message stays appearing in the Console of the browser, but, the code I posted on my question (and the code posted by SO user player0 in their answer) works, it seems to me that the delay of the response using IMPORTXML
might be due its buggy functionality and/or some restriction Google detected by doing multiple requests.
So, here are my tips about this:
IMPORTXML
function - as I experienced it.This is the spreadsheet with the desired results - if anyone is interesed1.
1 Check the "Results-mix" sheet (which contains both the code I manage to create and the code provided by player0 in their answer).
If you really want to get similar results in a less convoluted way, consider use another strategy for web-scrapping or use official APIs - when available.