Applescript结果(链接为文本)到URL

时间:2018-04-29 19:32:16

标签: url encoding applescript

似乎并不像我想象的那么容易。

我的脚本从网站中提取链接网址

截至目前,生成的网址只是文字,我需要将它们作为网址(剪贴板或变量)输出,以将其粘贴到电子邮件中

我尝试了各种各样的事情,从先保存到rtf文件,然后将其读取/粘贴到我的电子邮件正文中,或者通过剪贴板复制粘贴。

任何帮助都会很棒,因为我无法在2天内解决这个问题。感谢

--prompt for keyword
display dialog "Keyword or Sentence" default answer "mad dog" buttons {"Done"} default button 1
set Keyword to text returned of the result

--create URL filter from Keyword
set my text item delimiters to " "
delay 0.2
set split_list to every text item of Keyword -- split in to list of everything between the spaces
set my text item delimiters to "-"
set Filter to (split_list as text) -- join, using the - as the delimter

--Open Pages
set site_url to "https://teespring.com/search?q=" & Keyword
tell application "Safari"
    activate
    open location site_url
end tell

-- wait until page loaded
property testingString : "Help" --Text on website to look for

set pageLoaded to false
tell application "Safari"
    repeat while pageLoaded is false
        set readyState to (do JavaScript "document.readyState" in document 1)
        set pageText to text of document 1

        if (readyState is "complete") and (pageText contains testingString) then set pageLoaded to true
        delay 0.2
    end repeat
end tell

-- get number of links
set theLinks to {}
tell application "Safari" to set num_links to (do JavaScript "document.links.length" in document 1)
set linkCounter to num_links - 1
-- retrieve the links
repeat with i from 0 to linkCounter
    tell application "Safari" to set end of theLinks to do JavaScript "document.links[" & i & "].href" in document 1
end repeat
theLinks
set nonExcludedURLs to {}

--Filter URLs
repeat with i from 1 to length of theLinks
    if item i of theLinks contains Filter then

        set end of nonExcludedURLs to item i of theLinks
    end if
end repeat
nonExcludedURLs


on page_loaded(timeout_value)
    delay 2
    repeat with i from 1 to the timeout_value
        tell application "Safari"
            if (do JavaScript "document.readyState" in document 1) is "complete" then
                set nonExcludedURLs to {}

                return true
            else if i is the timeout_value then
                return false
            else
                delay 1
            end if

        end tell
    end repeat
    return false
end page_loaded

1 个答案:

答案 0 :(得分:0)

找到解决方案。也许我描述的问题并不是很好。

我只需要使用以下代码将结果url从一个文本块拆分为单行:

{{1}}