Как найти одинаковое значение между двумя списками в AppleScript? - PullRequest
0 голосов
/ 31 марта 2019

Я работаю на внутреннем веб-сайте, на котором есть список данных, перечисленных в следующем порядке:

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 голосов
/ 07 апреля 2019

Я нахожу это, просто нужно добавить повтор в список с предметом и предметом +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
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...