I've searched for a while trying to find a way in Postman to extract a HTML description list value from the response body where the description list contains multiple values.
Example of response body:
<dl>
<dd>Fruit</dd>
<dt>Apple</dt>
<dd>Vegetable</dd>
<dt>Carrot</dt>
</dl>
How do I just get just the Vegetable value? I've tried using the following
const $ = cheerio.load(pm.response.text())
console.log('Vegetable', $('dt').text())
This then returns both values
"Vegetable" "AppleCarrot"
The Fruit & Vegetable values will change once the request is rerun, this means I'm unable to go just based off their names.
I'm probably over thinking this, thanks in advance.
EricG posted the following above.
JQuery allows you to filter based off order using the following:
const $ = cheerio.load(pm.response.text())
console.log('Vegetable', $('dt').first().text())
Alternatively to the above if you need to go further down the list you can use:
const $ = cheerio.load(pm.response.text())
console.log('Vegetable', $('dt').eq(0).text())
Changing the value in .eq(#) starting from 0 will then following the items down the list.
Related
This is the output when printing my ${element}:
I wish to obtain the data of the first child of my ${element} that has a type: "text" and data valid duration (hours:minutes:seconds). In my case I want to obtain "5:01".
However, when trying to obtain all the children using ${element}.children() I get the following:
Basically there is no data and no type which I can check/obtain. What am I doing wrong?
From the log image I can see children property is an array not a function.
Following Code should get you the desired data.
element.children.find(child => child.type == 'text').data;
${element}.children().first().data()
So I'm new with Axios and I'm trying to make a Discord bot that takes info from an api website and uses it. The issue is the data given looks like:
{"status":1,"size":1,"result":[{"number":"9999", and so on.
How do I get the data inside of the [ ]? I tried:
var teamNumber = response.data.result.number
but it doesn't work.
I can get response.data.status, but not result.number
TLDR: how to get 9999 from {"result":[{"number":"9999", ?
result is an array; if you want to get the first element from it (and get that element's "number" field) you'd do:
console.log(response.data.result[0].number);
If you want to loop over them you'd do:
response.data.result.map(el => {
console.log(el.number);
});
I'm bulding a datagrid based on AngularJS and i got stucked on filter function.
I need to build a filter that interacts with the json to tell me if the value filtered was found or not found. The filter must be applied to generic jsons
I have the following json
var json = [{
"id":"1",
"name":"Homer",
"Role":"Analyst",
"Found":"true"
},{
"id":"2",
"name":"Maggie",
"Role":"Manager",
"Found":"true"
},
{
"id":"3",
"name":"Lisa",
"Role":"CEO",
"Found":"true"
},]
If i type "Li" or "Mana" on a search text box, Lisa and Maggie object must be shown because "Li" is part of Lisa's name and "Mana" is part of Manager role name and found key on Homer object must be set to false
Use ng-repeat with |filter is not an option, since I got lot of things going on like submenus on each row, colspans, etc
Thanks
You can try to do the filter in the controller using $filter avoiding the ng-repeat.
$filter('filter' )(Json, textToFilterBy);
Here is the Docs for $filter
https://docs.angularjs.org/api/ng/filter/filter
Here is an example of it working in a controller.
https://jsfiddle.net/Michael_Warner/khLhLou8/6/
I have a really big excel file with first row blank, second row with header and rest rows containing data.
I need to select only part of data from that file.
Because it should be done on client side in javascript I decided to use AlaSql library (alasql.org), where I can precisely select data I need with sql language.
Fe: first I count number of rows than select some of data (with headers) using range:
var sql = "SELECT value COUNT(*) FROM FILE(?,{headers:true})"; //count rows
alasql(sql,[event],function(numberofrows){
var sql2 = "select column1, column2 from FILE(?, headers:true,range:'A2:Z"+numberofrowss"'})";
//I need only two columns I can use here where/having/limit etc. conditions
alasql(sql2,[event],function(res){
... // other steps
}}
Is there more effective way to do the job (not counting rows first)?
Maybe it can be used something similar to range defined like 'A2:ZZ'?
Using range A2:A10000000 consumes all memory...
Any suggestions? Other library? Maybe there is a way to remove blank row first?
Are you tried to import data without range?
I never seen this library before (now thank you) and just used sample file with data like you described and examples from lib docs and got correct results:
alasql('SELECT header1, header2 FROM XLS("https://dl.dropboxusercontent.com/u/802266/a.xls",{headers:true})',[],function(data){
console.log(data);
});
result:
0: Object
header1: "aaa1"
header2: "aaa2"
1: Object
header1: "sss1"
header2: "sss2"
2: Object
header1: "xxx1"
header2: "xxx2"
`Working example: http://jsfiddle.net/xdfyxupL/
Also if you still need rows count, you can use ROWNUM
I have 2 questions based on the graphic below:
How can I tell if one of the 'data-conversationmessageuserid' data attributes with a specific value exists - say 1000000003? I believe data selectors is what I need and have tried the following but its not working yet:
if($('#conversationsInBoxMessagesWrapperDIV')['data-conversationmessageuserid=1000000003']) {
// do something
}
How could I get all the 'data-conversationmessageuserid' data attributes into an array and the loop through them? I'm still playing with this code but its far from publishable. Trying to use .map
.map(function()
thankyou so much
Try:
if($('#conversationsInBoxMessagesWrapperDIV [data-conversationmessageuserid=1000000003]').length)
or
$('#conversationsInBoxMessagesWrapperDIV').find('[data-conversationmessageuserid=1000000003]') //Or children only to look at one level.
To get all the data values you could do:
var conversationmessageuserids = $('#conversationsInBoxMessagesWrapperDIV').children().map(function(){
return $(this).data('conversationmessageuserid');
}).get();
jQuery supports data attributes: http://api.jquery.com/data/
So you could do if($('#conversationsInBoxMessagesWrapperDIV').data('conversationmessageuserid') === 1000000003)