evaljs returns nil even though it shouldn't? - scrapy

The following code ...
splash:evaljs('document.querySelectorAll("iframe.iframe-container.js-oddset-game-iframe")[0].contentDocument.querySelectorAll("td.leftText a.eventLink").length')
... returns 8 - i.e. there are 8 nodes in the array.
However, when I then try to return the nodeList (array) directly, the result is nil? Obviously a table should be returned since an array is returned from the javascript code.
Is this a bug in Splash? Can't Splash handle access to elements in iframes? I have the --js-cross-domain-access option on too.

It is not a bug. iframes are only available when you use the render.json endpoint with the iframes=1 parameter. When you use that you cannot run a custom Lua script.
Refer to the documentation: https://splash.readthedocs.io/en/stable/api.html#render-json
And this answer: https://stackoverflow.com/a/44682917/4082726

Related

ASSIGN fails with variable from debugger path

I am trying to assign the value of this stucture path to a fieldsymbol, but this path does not work because it has a table in it's path.
But with in the debugger this value of this path is shown correctly.
Is there a way to dynamically assign a component of a table line to a fieldsymbol, by passing one path?
If not then I will just read the table line and then use the path to get the wanted value.
ls_struct (Struct)
- SUPPLYCHAINTRADETRANSACTION (Struct)
- INCL_SUPP_CHAIN_ITEM (Table)
- ASSOCIATEDDOCUMENTLINEDOCUMENT (Element)
i_component_path = |IG_DDIC-SUPPLYCHAINTRADETRANSACTION-INCL_SUPP_CHAIN_ITEM[1]-ASSOCIATEDDOCUMENTLINEDOCUMENT|.
ASSIGN (i_component_path) TO FIELD-SYMBOL(<lg_value>).
IF <lg_value> IS NOT ASSIGNED.
return.
ENDIF.
<lg_value> won't be assigned
Solution by Sandra Rossi
The debugger has its own syntax and own logic, it doesn't apply the ASSIGN algorithm at all. With ABAP source code, you have to use ASSIGN twice, the first one to reach the internal table, then you select the first line, and the second one to reach the component of the line.
The debugger works completely differently, the debugger code works only in debug mode, you can't call the code from the debugger (i.e. if you call it, the kernel code used by the debugger will fail). No, there's no "abappath". There are the XSL transformation objects (xpath), but it's slow for what you ask.
Thank you very much
This seems to be a rather unexpected limitation of the ASSIGN statement. Probably worth a ticket to SAP's ABAP language group to clarify whether it's even a bug.
While this works:
ASSIGN data-some_table[ 1 ]-some_field TO FIELD-SYMBOL(<lv_source>).
the same expressed as a string doesn't:
ASSIGN (`data-some_table[ 1 ]-some_field`) TO FIELD-SYMBOL(<lv_source>).
Alternative 1 for (name) of the ABAP keyword documentation for the ASSIGN statement says that "[t]he name in name is structured in the same way as if specified directly".
However, this declaration is immediately followed by "the content of name must be the name of a data object which may contain offsets and lengths, structure component selectors, and component selectors for assigning structured data objects and attributes in classes or objects", a list that does not include the table expressions we would need here.

Unable to observe an array of objects (mobx)

According to the docs: https://mobx.js.org/refguide/array.html
I should be able to observe an array.
observe(listener, fireImmediately? = false) Listen to changes in this
array. The callback will receive arguments that express an array
splice or array change, conforming to ES7 proposal. It returns a
disposer function to stop the listener.
However I'm getting an exception when I do so within my app:
core.js:1350 ERROR Error: Uncaught (in promise): Error: [mobx] Cannot obtain administration from Neil Clayton,Ralph Lambert,Suzie Legg
at invariant (mobx.module.js:2652)
at fail$1 (mobx.module.js:2647)
at getAdministration (mobx.module.js:1967)
at observeObservable (mobx.module.js:3606)
at observe (mobx.module.js:3603)
at ObjectChangeTracker.webpackJsonp.683.ObjectChangeTracker.installObserverDirectlyOn (orm-change-detection.ts:258)
I'm unsure why getAdministration() is falling through.
I was under the impression I could pass anything into observe() (either a JS Object, real class or array thereof).
Am I mistaken that I can observe an array?
It turns out I was trying to observe a direct 'Array'.
This was happening because I was iterating the parent object keys, and getting the values by doing parent[propertyName]. Where 'propertyName' is provided by some other object (i'm intentionally leaving out specifics so as to not complicate my answer).
This was a couple of days ago now, but from memory this caused access via a getter, which had a side effect (returned a sorted array, new object, that wasn't observable).
If instead I got the value by the private field directly, and then observed the actual ObservableArray, my problems disappeared.
So, no longer convinced my question is valid.
Code is here: https://github.com/scornflake/scheduler
(but not expecting anyone to take a look, it's reasonably convoluted at the moment)

Simplexml get path from variable

Is there a way to pass the path to a simplexml node as a variable?
This is what I tried:
//set the path to the node in a variable
$comp = 'component->structuredBody->component';
echo count($xml->component->structuredBody->component); //=== 13
echo count($xml->$comp); //===0
echo count($xml->{$comp});//===0
What you need is XPath, and more specifically SimpleXML's xpath() method. Instead of traversing using PHP's -> operator, you would traverse using XPath's / operator, but otherwise, could achieve exactly the effect you wanted:
$comp = 'component[1]/structuredBody[1]/component';
echo count( $xml->xpath($comp) );
You might think that this could be simplified to 'component/structuredBody/component', but that would find all possible paths matching the expression - that is if there are multiple structuredBody elements, it will search all of them. That might actually be useful, but it is not equivalent to $xml->component->structuredBody->component, which is actually shorthand for $xml->component[0]->structuredBody[0]->component.
A few things to note:
Unlike most operations with SimpleXML, the result is an array, not another SimpleXML object (think of it as a set of search results). It is therefore vital that you check it is not empty before accessing element 0 as an object.
As you can see in the example above, XPath counts from 1, not 0. I don't know why, but it's caught me out before, so I thought I'd warn you.
The library SimpleXML is built on supports only XPath 1.0;
examples you see online for XPath 2.0 may not work.
XPath 1.0 has no notion of a "default namespace", and SimpleXML doesn't automatically register namespace prefixes for use in XPath, so if you're working with namespaces, you need to use registerXPathNamespace().

Mule MEL usage difference

I have been using different forms of Mule's Expression language.
I couldn't figure out the difference between
#[flowVars.myVariable]
and
#[flowVars['myVariable']]
They both give the result when there is a variable. But why do they behave differently when the variable is not present?
Like if the variable being called is not available, then the first expression would result in a exception. Whereas the second expression just gives out a warning or prints out as is, if in a logger message.
Why is this difference?
Also when going through the documentation for Mule 3.6 I found that the second expression is not longer shown in the documentation.
Is the expression #[flowVars['myVariable']] being deprecated?
The difference comes from the way MVEL deals with these two different ways of accessing map entries.
#[flowVars['myVariable']] is equivalent to flowVars.get('myVariable'), which does not fail if the flowVars map does not contain the 'myVariable' entry,
#[flowVars.myVariable] treats the flowVars map as a virtual object, leading to an exception if the 'myVariable' entry is missing because in this case it doesn't resolve to a map get but instead to directly using an object member (either a field or a method), which must exist before being accessed.
I don't think #[flowVars['myVariable']] could be deprecated since it's a core feature provided by MVEL.
Reference: http://mvel.codehaus.org/MVEL+2.0+Property+Navigation#MVEL2.0PropertyNavigation-MapAccess
David has given a nice explanation around your question. To extend that explanation I would just like to add that you can use #[flowVars.?myVariable] to make your code null safe. This is equivalent to #[flowVars['myVariable']].
Regarding #[header:originalFilename], as David said this is not MEL. You can get a list of non-mel expressions which are commonly used in Mule applications in the following link.
http://www.mulesoft.org/documentation/display/current/Non-MEL+Expressions+Configuration+Reference

Signalr-objc getting Return value

I am using signalr-objc currently and trying to make an app that interacts with another web app. The hub has been written so that it returns values and the javascript is able to get these and perform certain actions depending on the return.
I want to try and do the same with in objective-c but I am not sure how to write it. I use this line to join a group.
[myhub invoke:#"joinGroup" withArgs:joinParam];
and something like
int join = [myhub invoke:#"joinGroup" withArgs:joinParam];
does not seem right. So is there some way of doing this??
Since -invoke:withArgs: returns no value, you're not doing the right thing trying to assign a value to join.
If you need to determine if there was a server response, you'd be better off using the alternate -invoke:withArgs:continueWith:. The block you provide to the latter argument receives an object (a reply from the server); at the very least, you could check it inside that block to be sure it's not nil.