gpt4 book ai didi

applescript - 我需要在 AppleScript 中对字符串进行 URL 编码

转载 作者:行者123 更新时间:2023-12-04 23:01:15 24 4
gpt4 key购买 nike

我的脚本会在网站上搜索歌曲,但是当有空格无法搜索时,您必须添加下划线。我想知道是否有办法用下划线替换我的空格。
你能不能用我现在的代码告诉我怎么做?

set search to text returned of (display dialog "Enter song you wish to find" default answer "" buttons {"Search", "Cancel"} default button 1)
open location "http://www.mp3juices.com/search/" & search
end

最佳答案

备注 : 解决办法不再适用于 Big Sur (macOS 11) - 这听起来像是一个错误;如果您有更多信息,请告诉我们。
请尝试以下操作:

set search to text returned of (display dialog "Enter song you wish to find" default answer "" buttons {"Search", "Cancel"} default button 1)
do shell script "open 'http://www.mp3juices.com/search/'" & quoted form of search
end
您需要的是 URL 编码(即,对字符串进行编码以安全包含在 URL 中),这不仅仅是替换空格。 open幸运的是,命令行实用程序会为您执行此编码,因此您可以直接将字符串传递给它;您需要 do shell script调用 open , 和 quoted form of确保字符串未经修改地传递(稍后由 open 进行 URI 编码)。
如您所见,URL 编码类型 open执行用 %20 替换空格, 不是下划线,但这应该仍然有效。

关于applescript - 我需要在 AppleScript 中对字符串进行 URL 编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23852182/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com