Applescript - 检查URL列表是否包含列表中的任何单词

时间:2018-05-11 18:51:44

标签: web-scraping applescript

我有两个清单。列表A包含URL,列表B包含单词。我需要返回包含任何单词的每个URL(过滤)。

我已设法检查是否为true / false但不返回包含任何字词的网址。

set theURLs to {"www.audi.com", "www.vw.com", "www.suzuki.com"} as text
set KeywordFilter to {"dodge", "audi", "chevy"}
set doesContain to containsItems from KeywordFilter against theURLs


on containsItems from qList against theText
    set pageURLs to {}
    repeat with anItem in qList
        if theText contains anItem then return true
    end repeat
    return false
end containsItems

我是否需要另一个循环来返回字符串中匹配的URL?

感谢大家的帮助。

1 个答案:

答案 0 :(得分:1)

将列表强制转换为文本

set theURLs to {"www.audi.com", "www.vw.com", "www.suzuki.com"} as text

是一个坏主意,结果是 - 取决于text item delimiters - "www.audi.comwww.vw.comwww.suzuki.com"

要比较两个列表,您需要两个循环

set theURLs to {"www.audi.com", "www.vw.com", "www.suzuki.com"}
set KeywordFilter to {"dodge", "audi", "chevy"}
set foundURLs to containsItems from KeywordFilter against theURLs

on containsItems from qList against theText
    set pageURLs to {}
    repeat with aText in theText
        repeat with anItem in qList
            if aText contains anItem then set end of pageURLs to contents of anItem
        end repeat
    end repeat
    return pageURLs
end containsItems