Applescript:在curl中用ASCII替换(

发布于 2024-10-10 19:41:29 字数 118 浏览 5 评论 0原文

我正在尝试使用带有“(”的域名的curl,通过使用applescript中的curl,但这不起作用

我一直在尝试使用awk和sed,但失败了。

任何人都可以帮助我吗将“(”替换为正确的代码。

I am trying to use curl with a domain name with a "(" in it, by using curl from applescript, but this does not work

I have been bumbling around trying to use awk and sed, but failing.

Can anyone help me please to replace the "(" with the correct code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

静水深流 2024-10-17 19:41:29

您的示例中的域名不包含括号。网址确实如此。

您可以使用 sed 替换括号,如下所示:

sed -e 's/(/%28/g' -e 's/)/%29/g'

您可能还需要替换空格:sed 's/ /%20/g'

然而,curl 应该能够很好地处理 URL 中的括号。你说它“不起作用”根本没有传达任何信息。您应该准确地发布您正在做什么、结果与您的期望有何不同以及您收到的错误消息。

猜测您可能会收到诸如“-bash:意外标记'('附近的语法错误”之类的错误,可以使用正确的引用来修复该错误:

curl "api.themoviedb.org/2.1/Movie.search/en/xml/key/Fargo (1996)"

但是,当我尝试它时,我从当我以各种组合进行上述替换时(包括尝试在空格中使用下划线),我根本没有得到任何响应(但这可能是因为我没有 API 密钥)。似乎是括号有问题,但是无论如何

,查看他们的文档< /a>,他们给出了如何包含日期的示例:

http://api.themoviedb.org/2.1/Movie.search/en/xml/APIKEY/Transformers+2007

The domain name in your example doesn't include parentheses. The URL does.

You can replace the parentheses using sed like this:

sed -e 's/(/%28/g' -e 's/)/%29/g'

You may also need to replace the space: sed 's/ /%20/g'.

However, curl should be able to handle parentheses in the URL just fine. You say it "does not work" which conveys no information at all. You should post exactly what you're doing, exactly how the result differs from your expectations and exactly what error messages you're getting.

Guessing that you may be getting an error such as "-bash: syntax error near unexpected token '('", that can be fixed using proper quoting:

curl "api.themoviedb.org/2.1/Movie.search/en/xml/key/Fargo (1996)"

However, when I try it, I get an "400 Bad Request" message from the host. When I do the substitutions above in various combinations (including trying an underscore for the space), I get no response at all (but that's probably because I don't have an API key). In any case, it doesn't appear to be the parentheses that are problematic, but the space.

Anyway, looking at their documentation, they give an example of how to include a date:

http://api.themoviedb.org/2.1/Movie.search/en/xml/APIKEY/Transformers+2007
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文