Applescript|提取最高整数并创建从0到最高整数的数字

Applescript|提取最高整数并创建从0到最高整数的数字,applescript,filtering,Applescript,Filtering,我有一个脚本返回以下结果: 现在,我需要找到最高的整数(在本例中为&p=29),并在本例中创建从最高整数开始的新字符串 到目前为止,我使用以下代码提取了所需的URL: set AllUrls to {"https://XY.com/search?q=mad%20dog&p=26", "https://XY.com/search?q=mad%20dog&p=29", "https://XY.com/shop/General-Mad-Dog-Mattis-For-PrN"}

我有一个脚本返回以下结果:

现在,我需要找到最高的整数(在本例中为&p=29),并在本例中创建从最高整数开始的新字符串

到目前为止,我使用以下代码提取了所需的URL:

set AllUrls to {"https://XY.com/search?q=mad%20dog&p=26", "https://XY.com/search?q=mad%20dog&p=29", "https://XY.com/shop/General-Mad-Dog-Mattis-For-PrN"}

-- FILTER PAGING URLS
set PagingFilter to "&p="
set PagingUrls to {}
repeat with i from 1 to length of AllUrls
    if item i of AllUrls contains PagingFilter then

        set end of PagingUrls to item i of AllUrls
    end if
end repeat
PagingUrls -- returns {"https://XY.com/search?q=mad%20dog&p=26", "https://XY.com/search?q=mad%20dog&p=29"}
还有一个小脚本,用于从URL中提取最后2位数字:

set alphabet to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
set myURLs to {"https://XY.com/search?q=mad%20dog&p=26", "https://XY.com/search?q=mad%20dog&p=29"}
set the text item delimiters of AppleScript to ¬
    {space} & characters of the alphabet & {".", "_"}
set a to text items of myURLs as text

get last word of a --> returns "21"


set numlist to {}
repeat with i from 1 to count of words in a

    set this_item to word i of a
    try
        set this_item to this_item as number
        set the end of numlist to this_item

    end try

end repeat
numlist -- returns {26, 29}

这是另一种方法

它用
文本项分隔符
按分隔符
&p=
拆分URL。如果存在分隔符,则获取整数(分隔符的右侧),如果当前值高于上一个值,则将其另存为
maxValue

然后使用循环创建页面URL列表

set AllUrls to {"https://XY.com/search?q=mad%20dog&p=26", "https://XY.com/search?q=mad%20dog&p=29", "https://XY.com/shop/General-Mad-Dog-Mattis-For-PrN"}

set maxValue to 0
set baseURL to ""
set TID to text item delimiters
set text item delimiters to "&p="
repeat with anURL in AllUrls
    set textItems to text items of anURL
    if (count textItems) is 2 then
        set currentValue to item 2 of textItems as integer
        if currentValue > maxValue then set maxValue to currentValue
        set baseURL to item 1 of textItems & "&p="
    end if
end repeat
set text item delimiters to TID
set pageURLs to {}
repeat with i from 0 to maxValue
    set end of pageURLs to baseURL & i
end repeat

谢谢@vadian!是我错了,还是这个“只是”返回具有最高整数的URL?或者它应该返回一个从整数0到最大值的URL列表吗?结果(所有页面URL作为一个列表)在变量
pageURLs
Ah中,我的错:)我想我应该在查看脚本时,只是忘记了输出正确的变量:)非常感谢,比我的方法简单多了!