0

I created a script to return some credit card informations from an internal website

                            <a href=\"/web/Support.aa/aa/g55erefesfsfsf/4.g.g.5.24.54\">
                                CC<br>Info
                            </a>

                    ", "

                            Visa (9999)

                    ", "

                            Visa (8888)

                    ", "

                            Visa (7777)

                    ", "

                            Visa (666)

                    ", "

                            Alipay

                    ", missing value, missing value, missing value}

I have two issue with my script,

  1. I can't get rid of the first link with is not a CC numbers tried : set myRawData to items 2 thru -1 of myRawData as string but don't seems to work.

  2. I don't manage to remove all the missing values.

  3. Can I remove some entry from the list that contain "none" ?

Here is my full script

tell application "Google Chrome"
    tell active tab of window 1 to set myRawData to execute javascript "var outPut=[]; var arr=document.getElementsByClassName('sortable fraudScoringTransactionCCSummary');for (var i in arr) {outPut.push(arr[i].innerHTML)};outPut;"
end tell

## set myRawData to items 2 thru -1 of myRawData as string -- not working
set myNewList to {}

repeat with each from 1 to count of items of myRawData
    set itemOnMyList to item each of myRawData
    if itemOnMyList is in myRawData and itemOnMyList is not in myNewList then set end of myNewList to itemOnMyList
end repeat

## not sur
##set myNewList to items 2 thru -1 of myNewList  -- not working

set countHowManyCC to count myNewList


return countHowManyCC
  • First of all, the first content set in a code block in your OP, the info returned is not in the form of a list as posted because it's missing an opening curly brace and a opening double quote {". Second, you asked "Can I remove some entry from the list that contain "none" ?", well there are no entries in the output you posted that contain "none"! Do you perhaps actually mean "missing value"? – user3439894 May 11 '18 at 11:16
1

Using the returned output information posted in your OP while adding the missing opening curly brace and a opening double quote {" so as to have it compile as a list, the following example AppleScript code filters out the first item of the list as well as the items containing missing value in order to return a count of items that represent the data.

set myRawData to {"<a href=\"/web/Support.aa/aa/g55erefesfsfsf/4.g.g.5.24.54\">
                                CC<br>Info
                            </a>

                    ", "

                            Visa (9999)

                    ", "

                            Visa (8888)

                    ", "

                            Visa (7777)

                    ", "

                            Visa (666)

                    ", "

                            Alipay

                    ", missing value, missing value, missing value}


set myRawData to items 2 thru -1 of myRawData

set myNewList to {}
repeat with i from 1 to count myRawData
    if item i of myRawData does not contain missing value then
        copy item i of myRawData to end of myNewList
    end if
end repeat

return count myNewList

The following example AppleScript code adds a second filter to handle items containing "none":

set myRawData to items 2 thru -1 of myRawData

set myNewList to {}
repeat with i from 1 to count myRawData
    set thisItem to item i of myRawData
    if thisItem does not contain "none" then
        if thisItem is not missing value then
            copy item i of myRawData to end of myNewList
        end if
    end if
end repeat

return count myNewList

Note: The example AppleScript code is just that and does not employ any error handling and is meant only to show one of many ways to accomplish a task. The onus is always upon the User to add/use appropriate error handling as needed/wanted.

  • That seems to generate a duplicate on the first item each time but then I guess I can remove the fist item – Kevin May 11 '18 at 12:20
  • @Low Risk, In your comment you said, "That seems to generate a duplicate on the first item each time but then I guess I can remove the fist item" and I fail to see what you mean as the example AppleScript code does no such thing! It remove the first item of the list and any item containing missing value and there are absolutely no duplicates! That is of course there are no duplicates in the list other then missing value. In other words, the example list originally contains 9 items, the first item is removed, then the missing value items are removed thus leaving 5 items no dups! – user3439894 May 11 '18 at 12:47
  • I'm testing with live data with my internal website, and the first item (after the URL been removed) is added twice to the list, but that's fine because I just have to add "set myFinalList to items 2 thru -1 of myFinalList" and I get rid of it. What I mean for the "None" is some time when I have no transaction with credit card I have "None" instead in text, and I would like to exclude this from my list too. – Kevin May 11 '18 at 12:50
  • @Low Risk, The example AppleScript code I posted has absolutely no coding and or mechanism to duplicate an item! How you implemented the code is a different story all together! You need to start posting proper compilable examples of your output and code and what you expect the final output to look like! Do you want to filter out items containing missing value as well as "none", or just "none"? If just none then change missing value to "none". If both, then add another if statement directly after the first one and before the copy ... line of code. – user3439894 May 11 '18 at 13:34
  • @Low Risk, I've updated my answer to include filtering items containing "none". – user3439894 May 11 '18 at 13:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .