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并使用“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
推荐阅读
- apache-spark - 使用简单查询时,如何在 Hive-Spark 中修复“org.apache.hadoop.hive.ql.metadata.HiveException”?
- python - 使用 Pandas pivot_table 嵌套小计“所有”行
- python - 二叉树的高度 - 迭代
- c - 使用 bazel 制作共享对象时不能使用全局
- java - 如何使环境变量在 JAR 文件中工作?
- filter - 如何按 BlankNode id 过滤
- node.js - 如何忽略 git push 上的公用文件夹?
- java - onCreateViewHolder 与 android.support.v7 中的 onCreateViewHolder 发生冲突
- javascript - 如何将自定义属性添加到 FullCalendar 中的每个时间段单元格?
- json - 使用新键名聚合的 JSON 数组合并