This document requires 'TrustedScriptURL' assignment in Google Sheets - google-sheets

I have a Google Spreadsheet where I have the following information on specific cells in the sheet:
Cell B1: Has the URL http://www.google.com.co/search?q=NASA+watching+now%3A+site%3Awww.youtube.com
Cell B2: has the following formula: =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:
Title: Text (in the h3 HTML tag of the result item).
Url: Link (in the <a> HTML tag of the result item)
Description: Text next to the thumbnail 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:
Google Chrome update - making security stricter.
Chrome extensions - try to disable such extensions and try again.
CPS (Content-Security-Policy) - must be honest = I don't understand this point; it's from the website to scrape the data OR from Google Sheets the CPS is the root cause?
The solutions given to this problem are in Python - with the use of DOMPurify - as is described in this answer, but, I don't know and neither have found any clues about this problem and its solution in Google Spreadsheets.
I've tried:
Recover previous working Google Spreadsheet version - the result is that the formula re-evaluates and no result is returned; looking in Console, the This document requires 'TrustedScriptURL' assignment message shows.
Disable Google Chrome installed extensions - I only have AdBlock (this code was working without issues), anyway, I turned off, reload the spreadsheet and the error mentioned above raises in Console.
Using another page - I tried with Wikipedia and Wiki.fandom and it works - i.e. data is returned. Probably in this case, Google injected in their searcher an script for avoid injection? - I'm really not sure, only speculating/rambling here.
Another possible cause I consider is maybe my IP was blacklisted or blocked, but, I'm not sure.
My browser information:
Chrome version: 98.0.4758.82 (Build oficial) (64 bits) (cohort: Stable)
Windows 10 Version 21H2 (Build 19044.1466)
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.

I will just leave this here:
=INDEX(UNIQUE(REGEXREPLACE(QUERY(IMPORTXML(A1, "//a/#href"),
"where Col1 contains 'youtube.com/'"), "\/url\?q=|&sa=.*", )))
=IMPORTXML(A1, "//title")
=IMPORTXML(A1, "//h3")

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:
Check very closely how the page where the data will be extracted from and its structured before doing excessive requests - or you might face a significant delay in the response of the IMPORTXML function - as I experienced it.
Get more familiar with XPath and check if the data is dynamically generated in the page - this makes even harder to get the desired data using this way of scrapping.
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.

Related

What are the actual differences between the print() vs debugPrint() and log() in Flutter?

I am trying to create a util for logging.
I need to know the actual differences between print() vs debugPrint() and log().
Many answers I have seen are outdated or confusing. Also, some upvoted answers are contradict.
I am trying to print error messages in red color. I am using ANSI code to achieve it.
debugPrint("\x1B[31m HelloDebug \x1B[0m");
The above one print in red color.
But when i do the same using log(), its not printing in red color. Its escaping the ANSI code.
One thing I found out was log() has error parameter.
If i pass something as error , it handles red color by default.
Here in the first one using log, red is not coming because ANSI code is ignored. But in debugPrint using it's working fine. In third one it takes error red by default. But extra line is added even for empty string message.
Code:
Output:
Is it possible use ANSI code for making color text using log?
Because I have other ANSI code to make different color text.
I dont want use debugPrint because if I print some thing too frequently , the system ignore the logs.
After digging some time I found out that log function is implemented in c++ in the dart runtime.As the log function is external function in dart sdk.
external void log(
String message, {
DateTime? time,
int? sequenceNumber,
int level = 0,
String name = '',
Zone? zone,
Object? error,
StackTrace? stackTrace,
});
https://github.com/dart-lang/sdk/blob/main/runtime/lib/developer.cc
Also I see some different answers while digging.
The below answer says debugPrint only available inside widget class. Is it still true?
https://stackoverflow.com/a/52241553/9248098
EDIT:
While using debugPrint and when I launch app from Android studio terminal, the ANSI color is working in android but when I run it same in iOS its escaping the characters in same Android Studio terminal.
If ANSI code support is based on terminal support, I couldn't figure out why its having issue in same terminal in iOS.
It is well explained in this page Debugging Flutter apps programmatically
debugPrint() is similar to print() but with a throttles applied to prevents being dropped by Android’s kernel.
If you have linter setup on VSCode or other IDE, you will see this warning whenever you use print in your code. For more information, you can refer to Avoid print calls in production code.
To avoid the lint error, you can use kDebugMode with print or debugPrint instead.
if (kDebugMode) {
print('test print');
}
// OR
debugPrint('test debugPrint');
As for log(), it actually allows you to include more information on the logging output. For example, you can add the runtimeType and the relevant object in the log that can help you in debugging the code.
log(
'test log',
name: runtimeType.toString(),
error: myObj,
);
** btw I tried log with ANSI code log("\x1B[31m HelloDebug \x1B[0m");, it is working as expected.

Quickfixj- Custom FIX msg - 35=F not working for Multileg

I am using quickfixJ 2.3
To parse the FIX message , we have used
MessageUtils.parse(msgFactory,dd,inPutFixMsg, false)
I am able to place the list order ,multileg - 35= AB, AC order.
Now when I want to cancel the multileg order created by AB,
I just replaced 35=F, added 41 tag.
Now I am getting error while parsing in Message.parse : tag 600 appears more than once.
I am interested to know ,the other cancel( new order cancel, future cancel) working fine. Even I have mentioned the dd, then still why m I getting the error?
Or is there any other approach ?
You can't just change the message type (tag 35) and assume all the other tags are going to be compatible!
AB and F messages have different tags in their body. They are totally different messages!
The amount of stuff about FIX that you need to know exceeds what is appropriate for a StackOverflow answer. You really need to read some docs about how FIX messages are structured and decoded.

https://query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.xchange where pair in ("ARSARS")&env=store://datatables.org/alltableswithkeys

I have been using the following URL for the past 3 years without issue. However, it has stopped returning results.
URL:
https://query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.xchange where pair in ("ARSARS")&env=store://datatables.org/alltableswithkeys
Now returns the following:
<?xml version="1.0" encoding="UTF-8"?>
<query xmlns:yahoo="http://www.yahooapis.com/v1/base.rng" yahoo:count="0" yahoo:created="2017-11-02T09:33:25Z" yahoo:lang="en-AU">
<results/>
</query><!-- total: 9 -->
Notice how there are no results, it simply has the tag "results".
I have tried on this many different computers and browsers. I have also tried changing the currency combinations, but no luck.
Can anybody spot what I am doing wrong?
Yes, it looks like Yahoo has discontinued their Currency Converter API service.
I found a different site : https://currencylayer.com/
They let you request currency rates (1 USD = 168 other currencies). If you make less than 1000 requests per month, it is free (if you need more, they have different subscriptions : https://currencylayer.com/product).
You just need to sign up and receive your own Access Code. Once you have that, then you simply make the call http://apilayer.net/api/live?access_key= and it will return JSON of the other currency rates.
They also have code examples in PHP, JavaScript, and Java at https://currencylayer.com/documentation
Found it very easy to get started using their API right away.
I think the API is down.
I am similarly receiving "results"=nullfor the query:
http://query.yahooapis.com/v1/public/yql?q=select+%2A+from+yahoo.finance.xchange+where+pair+in+%28%22GBPEUR%22%29&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys
Setting diagnostics=true in the request yields:
`
[execution-start-time] => 7
[execution-stop-time] => 12
[execution-time] => 5
[http-status-code] => 999
[http-status-message] => Request denied
[content] => http://download.finance.yahoo.com/d/quotes.csv?s=GBPEUR=X&f=snl1d1t1ab
`
If anyone knows more than me about what this might imply I'd be glad to hear it!
Yahoo is aware of this issue and their engineers are working on it:
ref: https://forums.yahoo.net/t5/Yahoo-Finance-help/http-download-finance-yahoo-com-d-quotes-csv-s-GOOG-amp-f/td-p/387096
Very sadly and quite outrageously Yahoo decided to stop this service without any warning.
See admin message here
So many services depend on it, it's like Google saying they would suddenly stop their maps API... At this point I am blocking yahoo in our DNS so no one in our company will ever use Yahoo again since they are not a reliable entity.

Omniture Saint.ImportCreateJob

This is a very specific Omniture API question. Thought I'd check here if anyone encountered this problem since Omniture forum was not of much help -
Sending the following parameters to Omniture API Explorer here - https://developer.omniture.com/en_US/get-started/api-explorer#Saint.ImportCreateJob seems to work fine.
{
"check_divisions":"1",
"description":"OSRA job description: MyReportID, Products, 51",
"email_address":"my#email.com",
"export_results":"0",
"header":["Field1", "Field2"],
"overwrite_conflicts":"1",
"relation_id":51,
"report_suite_array":["MyReportID"],
"c_view":"SomeReportName"
}
But the call fails in the actual code with a 'Bad Request'. It seems like c_view parameter is expecting a certain value. The only documentation for c_view is that it expects a report name. I've tried report names and other values with no luck. Would appreciate any pointers from Omniture API users.
Thanks.
try using the relevant value from the classification_view chart. I know this is what you need for using the get/save classifications methods (I have used those methods, but not the Saint.ImportCreateJob method).
c_value is not required, so unless you plan on using it, it does not need to be present. It is supposed to be a classification_view https://developer.omniture.com/en_US/documentation/omniture-administration/r-classification-view.
It takes some trial and error to get this api working.
Here is an example of a call I use that works using the REST api over Java:
Request:
{
"check_divisions":1,
"description":"Report Test 1",
"email_address":"cdegroot#adobe.com",
"export_results":"0",
"overwrite_conflicts":0,
"relation_id":65,
"report_suite_array":["cdgdev"],
"header":["Key","Survey","Survey^Question","Survey^Question^Response","Engagement Index","Survey > Question > Response"]
}
Response:
"3387166"
Kind Regards C.

get DynamicSearchAd along with TextAd via Google Adwords API

Google provides nice examples of getting TextAd via API: https://code.google.com/p/google-api-adwords-php/source/browse/examples/v201209/BasicOperations/GetTextAds.php
I expected that getting DynamicSearchAd will be as easy as modifying line 54 to:
$selector->predicates[] = new Predicate('AdType', 'IN', array('TEXT_AD', 'DYNAMIC_SAERCH_AD'));
however for campaign with bunch of negative keywords, 0 postiive keywords and bunch of ads [ visible in the interface ] my result is buch of negative keywords and 0 ads, like they were not existing. I have googled for quite a long time already, but most recent post about keywordless ads is from 2012 and since then I believe that DynamicSearchAds went out from beta and are not available for everyone.
I played quite a little bit with sample example, changing fields [ like removing Headline and leaving only Id etc ], without success.
So my question is, how should I modify this example to obtain DSA ?
You've got missprint on constant in Predicate.
'DYNAMIC_SAERCH_AD' must be 'DYNAMIC_SEARCH_AD'

Resources