如何在AppleScript中找到两个列表之间的相等值?

时间:2019-03-31 14:17:23

标签: list applescript

我正在一个内部网站上,该网站具有按此顺序列出的数据列表:

Date - FirstName - Last Name
01/01/19 - demo - demo
01/01/19 - demo - demo
01/01/19 - demo - eg
01/01/20 - demo - demo

我正试图找出更改日期(“日期”标签)。

我为日期创建了一个列表,为名字和姓氏创建了另外两个列表,并将它们合并到最后一个列表中。

如何返回值开始更改的日期,例如

01/01/19-演示-例如:结果01/01/19吗?

到目前为止,这是我的脚本:

set creationDate to {}
set firstName to {}
set resultList to {}
set lastName to {}
try
    repeat with counter from 1 to 1000
        tell application "Safari"
            set myValue to do JavaScript "document.getElementsByClassName('auto-date-time')[" & counter & "].innerHTML;" in current tab of window 1
        end tell
        if myValue = missing value then
            exit repeat
        else if myValue is not equal to "" then
            set the creationDate to the creationDate & myValue
        end if
    end repeat
on error
    --
end try
set listSize to count of creationDate



try
    repeat with counter from 1 to 1000
        tell application "Safari"
            set myValue to do JavaScript "document.getElementsByClassName('sortable firstName')[" & counter & "].innerHTML;" in current tab of window 1
        end tell
        if myValue = missing value then
            exit repeat
        else if myValue is not equal to "" then
            set the firstName to the firstName & myValue
        end if
    end repeat
on error
    --
end try
set listSize to count of firstName

try
    repeat with counter from 1 to 1000
        tell application "Safari"
            set myValue to do JavaScript "document.getElementsByClassName('sortable lastName')[" & counter & "].innerHTML;" in current tab of window 1
        end tell
        if myValue = missing value then
            exit repeat
        else if myValue is not equal to "" then
            set the lastName to the lastName & myValue
        end if
    end repeat
on error
    --
end try
set listSize to count of lastName

set resultList to {}
repeat with i from 1 to count creationDate
    set end of resultList to {item i of firstName, item i of lastName}
end repeat







repeat with x from 1 to count of items of creationDate
    set n to item x of firstName
    set m to item x of lastName
    set d to item x of creationDate
    if n is not equal to m then return d
end repeat

1 个答案:

答案 0 :(得分:0)

我找到了,只需要在列表中添加带有item和item +1的重复项并使用“ IF”播放

tell application "Safari" to tell document 1 to tell (do JavaScript "
    [...new Set( document.getElementsByClassName('sortable firstName') )]
    .map( x => x.innerText.trim() );") ¬
    to set firstName to every text


tell application "Safari" to tell document 1 to tell (do JavaScript "
    [...new Set( document.getElementsByClassName('sortable descending created') )]
    .map( x => x.innerText.trim() );") ¬
    to set creationDate to every text

set myLinetoSave to ""
set dateofChante to ""

set listSize to count of firstName

repeat with each from 2 to count of items of creationDate
    set itemOnMyList to item each of firstName
    set itemOnMyListFuture to item (each + 1) of firstName  
    if itemOnMyList is not equal to itemOnMyListFuture then
        set myLinetoSave to each + 1
        set dateofChante to item (each + 1) of creationDate
        return dateofChante
    end if
end repeat