Bash - 如何从官方插件 WordPress 页面获取下载 url?

发布于 2024-11-30 23:13:34 字数 622 浏览 0 评论 0原文

我试图通过 bash 脚本直接从其官方年龄获取 WordPress 插件的下载链接。

例如,akismet 插件位于 http://wordpress.org/extend/plugins/akismet/

在HTML源代码中,我们可以很容易地识别下载链接在哪里:

<div class="col-3">
    <p class="button">
        <a href='http://downloads.wordpress.org/plugin/akismet.2.5.3.zip'>
            Download Version 2.5.3
        </a>
    </p>

我注意到“下载版本”一词在整个文件中只出现一次,就在我们想要获取的下载链接之后。

假设我不知道下载链接是什么。问题是如何过滤html代码以获得下载链接(以便稍后我可以将其与wget或curl一起使用)。我只知道插件页面的网址。如何过滤 html 代码以提取下载链接。

谢谢。

I'm trying to get the download link of wordpress' plugins via bash script directly from its official age.

For instance, the akismet plugin at http://wordpress.org/extend/plugins/akismet/

In the HTML source code we can easily recognize where the link for download is:

<div class="col-3">
    <p class="button">
        <a href='http://downloads.wordpress.org/plugin/akismet.2.5.3.zip'>
            Download Version 2.5.3
        </a>
    </p>

I noticed that the words "Download Version" only appear once in the entire file, just after the download link that we want to get.

Let's say I do not know what is the download link. The question is how can filter the html code in order to get the download link (so later I can use it with wget or curl). All I know is the plugin page url. How do I filter the html code in order to extract the download link.

Thank you.

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

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

发布评论

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

评论(2

木格 2024-12-07 23:13:34
nadav@shesek:~$ curl -s https://wordpress.org/extend/plugins/akismet/ | egrep -o "https://downloads.wordpress.org/plugin/[^']+"
https://downloads.wordpress.org/plugin/akismet.2.5.3.zip


nadav@shesek:~$ wget `curl -s https://wordpress.org/extend/plugins/akismet/ | egrep -o "https://downloads.wordpress.org/plugin/[^']+"`
--2011-08-20 16:43:33--  https://downloads.wordpress.org/plugin/akismet.2.5.3.zip
Resolving downloads.wordpress.org... 72.233.56.138, 72.233.56.139
Connecting to downloads.wordpress.org|72.233.56.138|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 27714 (27K) [application/octet-stream]
Saving to: `akismet.2.5.3.zip'

100%[============================================================================================================================================================>] 27,714      39.9K/s   in 0.7s    

2011-08-20 16:43:35 (39.9 KB/s) - `akismet.2.5.3.zip' saved [27714/27714]

请注意 grep 的 -o 开关,这使得它仅输出匹配的部分而不是整行。

nadav@shesek:~$ curl -s https://wordpress.org/extend/plugins/akismet/ | egrep -o "https://downloads.wordpress.org/plugin/[^']+"
https://downloads.wordpress.org/plugin/akismet.2.5.3.zip


nadav@shesek:~$ wget `curl -s https://wordpress.org/extend/plugins/akismet/ | egrep -o "https://downloads.wordpress.org/plugin/[^']+"`
--2011-08-20 16:43:33--  https://downloads.wordpress.org/plugin/akismet.2.5.3.zip
Resolving downloads.wordpress.org... 72.233.56.138, 72.233.56.139
Connecting to downloads.wordpress.org|72.233.56.138|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 27714 (27K) [application/octet-stream]
Saving to: `akismet.2.5.3.zip'

100%[============================================================================================================================================================>] 27,714      39.9K/s   in 0.7s    

2011-08-20 16:43:35 (39.9 KB/s) - `akismet.2.5.3.zip' saved [27714/27714]

Notice the -o switch for grep, that makes it output the matched part only instead of the entire line.

寄人书 2024-12-07 23:13:34

您可以尝试使用以下正则表达式:

href=['"](.*?)['"]>\s*Download Version [0-9.]+

You can try with following regex:

href=['"](.*?)['"]>\s*Download Version [0-9.]+
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文