Invalid XPath: string-join(.//div[#class="static"]/text(), "")? - xpath

The following works and produces a list:
xpath('.//div[#class="static"]/text()')
i want to return a single string instead
i tried:
xpath('string-join(.//div[#class="static"]/text(), " ")')
and
xpath('.//div[#class="static"]/string-join(text(), " ")')
both are invalid, what am i doing wrong?

You have two options:
Use
'\n'.join(response.css("div.static::text").extract())
Use processors in item loaders: this is by far the most elegant solution if you use this a lot: http://doc.scrapy.org/en/latest/topics/loaders.html.

Related

Filtering in Tablesorter. Unexpected behaviour

In my tablesorter I applied this addParser to the column I'm showing here in this question. And it works well, but I found an unexpected behaviour when I filter in a way.
The results without filtering will be like this next picture:
The code for the addParser is the next one:
$.tablesorter.addParser({
// set a unique id
id: 'kilogramos',
is: function(s) {
// return false so this parser is not auto detected
return false;
},
format: function(s) {
// format your data for normalization
return parseFloat(s.replace(' Kg','').replace('.',''));
},
// set type, either numeric or text
type: 'numeric'
});
If I use the ">=" it seems to apply the addParser, because I can get rid the "." and the " Kg" of and it finds the 11.689 Kg results.
But seems that if I don't use the operators like ">", or ">=", etc. the behaviour change and it needs the dot to find what you are trying to get. In the next pictures I show what I mean.
In this last picture, I don't use the operators and I doesn't find any results. Instead, it needs now the "." and also even the " Kg" it works. The next image proves that:
I just don't want to need this "." or " Kg" to be used in any case.
Any help? Thanks
I think all you're missing is a "filter-parsed" class in the header (demo)
<th class="sorter-kilogramos filter-parsed">Kg</th>

Seperate initials in freemarker

Is it possible to set points in initials?
For example to change MAW into M.A.W.
I tried keep_before, but it doesn't work.
?keep_before(" ")+". "}
Result: MAW.
Please help.
You could do it like:
${'MAW'?replace('','.')[1..]}
'MAW'?replace('','.') will result in .M.A.W., which you can "substring" by using the range [1..].
See
https://freemarker.apache.org/docs/ref_builtins_string.html#ref_builtin_replace
https://freemarker.apache.org/docs/dgui_template_exp.html#dgui_template_exp_stringop_slice
It's easiest to do with regular expressions: ${initials?replace('.', '$0.', 'r')}. It's maybe nicer if you wrap this into a #function though (<#function dotify(s)><#return s?replace('.', '$0.', 'r')></#function>, and then ${dotify(initals)}), especially if you need to do this on multiple places.
If your letters are in name try:
<#list 0..(name?length-1) as idx>${name[idx]}.</#list>

remove `\"` from string rails 4

I have params like:
params[:id]= "\"ebfd11a9-3aa4-415a-ba72-1b6796ea1bf6\""
And i want to get expected result as below:
"ebfd11a9-3aa4-415a-ba72-1b6796ea1bf6"
How can I do this?
You can use gsub:
"\"ebfd11a9-3aa4-415a-ba72-1b6796ea1bf6\"".gsub("\"", "")
=> "ebfd11a9-3aa4-415a-ba72-1b6796ea1bf6"
Or, as #Stefan mentioned, delete:
"\"ebfd11a9-3aa4-415a-ba72-1b6796ea1bf6\"".delete("\"")
=> "ebfd11a9-3aa4-415a-ba72-1b6796ea1bf6"
If this is JSON data, which it could very well be in that format:
JSON.load(params[:id])
This handles things where there's somehow escaped strings in there, or the parameters are an array.
Just Use tr!
params[:id].tr!("\"","")
tr! will also change the main string
In case you do not want to change main string just use :
params[:id].tr("\"","")
Thanks Ilya

How to generate "1. Do the homework" from "#Model.Number. #Model.Task" in razor?

I need to generate a string which looks like variable, dot, space, another variable.
The #Model.Number. #Model.Task or #(Model.Number). #(Model.Task) or #{Model.Number}. #{Model.Task} doesn't seem to compile.
The #Model.Number<text>. </text>#Model.Task works, but it generates a trashy <text> tag in the resulting html.
If I place all of these on a separate line:
#Model.Number
.
#Model.Task
then the result will render with an extra space between the number and the dot.
The #Model.Number#:. #Model.Task doesn't compile either.
Try this:
#(Model.Number). #Model.Task
Another solution:
#(Model.Number + ". " + Model.Task)

Printing this variable in smarty

I'm having an array $customPre. I want to print the element of the array "Please specify which fund". I am doing like this:
{$customPre.Please specify which fund}
But it's not working.
In this case you need to use PHP-like syntax that is similar to PHP: {$variable['key']}.
If In PHP you have:
$smarty->assign('customPre', array ('Please specify which fund' => 'This is value'));
In Smarty you need to use:
{$customPre['Please specify which fund']}
And the output for this will be:
This is value
I believe you cannot use in this case dot syntax ( {$customPre.Please specify which fund}) because it's probably looks for whitespaces in keys. Even adding quotes won't help.

Resources