我正在嘗試構建與以下 github 特定代碼等效的代碼,該代碼可用于查找可從https://runtime.fivem.net/artifacts/fivem/build_proot_linux/master下載的最新工件——下載鏈接看起來有些東西像https://runtime.fivem.net/artifacts/fivem/build_proot_linux/master/5901-5db768d8bbb973ba27c81e424aea2910144a3100/fx.tar.xz。
# Working code for github.com, needs to be converted to fivem.net
LOCATION=$(curl -s https://api.github.com/repos/someuser/somerepo/releases/latest \
| grep "tag_name" \
| awk '{print "https://github.com/someuser/somerepo/archive/" substr($2, 2, length($2)-3) ".zip"}') \
; curl -L -o file.zip $LOCATION
該檔案有一個遞增的版本號,但沒有一個序列號,后跟一個完全隨機的散列。
如何從https://runtime.fivem.net/artifacts/fivem/build_proot_linux/master的 HTML 頁面找到最新的下載鏈接?
uj5u.com熱心網友回復:
如果您想使用命令列工具決議 HTML,那么我建議您看一下適當的 HTML 決議器,例如西德爾:
$ xidel -s "https://runtime.fivem.net/artifacts/fivem/build_proot_linux/master/" \
-e '//a[@][1]/@href'
./5914-b600ff018d939f6a65e48994bf4a4192388435e7/fx.tar.xz
此外,不需要 Bash 腳本或任何其他工具,因為使用--follow/-f并且--download您可以立即下載檔案:
$ xidel -s "https://runtime.fivem.net/artifacts/fivem/build_proot_linux/master/" \
-f '//a[@][1]/@href' \
--download .
這會在當前目錄中下載“fx.tar.xz” 。當擴展名首先是“xz”時,我不建議手動輸入“file.zip” 。但是,您可以生成更合適的檔案名:
$ xidel "https://runtime.fivem.net/artifacts/fivem/build_proot_linux/master/" \
-f '//a[@][1]/@href)' \
--download 'artifacts-{extract($url,"master/(\d )-",1)}.tar.xz'
Retrieving (GET): https://runtime.fivem.net/artifacts/fivem/build_proot_linux/master/
Processing: https://runtime.fivem.net/artifacts/fivem/build_proot_linux/master/
Retrieving (): https://runtime.fivem.net/artifacts/fivem/build_proot_linux/master/5914-b600ff018d939f6a65e48994bf4a4192388435e7/fx.tar.xz
Save as: artifacts-5914.tar.xz
這會在當前目錄中下載“artifacts-5914.tar.xz” 。當您省略--silent/時-s,您將看到這些日志訊息。順便說一句,我不知道這個軟體,所以我假設它被稱為“神器”。
uj5u.com熱心網友回復:
我們可以構建使用lynx dump,如Easest way to extract the urls from an html page using sed or awk only -
#!/usr/bin/env bash
url_re='https://runtime.fivem.net/artifacts/fivem/build_proot_linux/master/([[:digit:]] )-([[:xdigit:]] )/fx.tar.xz'
newest_link_num=0
newest_link_content=
while read -r _ link; do
[[ $link =~ $url_re ]] || continue
if (( ${BASH_REMATCH[1]} > newest_link_num )); then
newest_link_num=${BASH_REMATCH[1]}
newest_link_content=$link
fi
done < <(lynx -dump -listonly -hiddenlinks=listonly https://runtime.fivem.net/artifacts/fivem/build_proot_linux/master)
echo "Newest link is: $newest_link_content"
在撰寫本文時,它以以下輸出結束:
最新鏈接是:https ://runtime.fivem.net/artifacts/fivem/build_proot_linux/master/5901-5db768d8bbb973ba27c81e424aea2910144a3100/fx.tar.xz
uj5u.com熱心網友回復:
我檢查了https://runtime.fivem.net/artifacts/fivem/build_proot_linux/master/和最新鏈接(版本 5902 即最新和版本 5484 即最新推薦)似乎有is-active類
<a class="panel-block is-active" href="./5902-3c88d7752be75493078c1da898337b0abc2652ff/fx.tar.xz" style="display: block;">
與舊版本相反。如果可能,您應該使用設計用于處理 HTML 的工具來處理 HTML hxselect,但是如果您不允許安裝此類工具,您可能會使用 GNUAWK來代替以下方式
wget -O - https://runtime.fivem.net/artifacts/fivem/build_proot_linux/master/ | awk 'BEGIN{RS="<|>"}/is-active/{sub(/^.*href="\./,"");sub(/".*/,"");print "https://runtime.fivem.net/artifacts/fivem/build_proot_linux/master"$0}'
獲得輸出
https://runtime.fivem.net/artifacts/fivem/build_proot_linux/master/5902-3c88d7752be75493078c1da898337b0abc2652ff/fx.tar.xz
https://runtime.fivem.net/artifacts/fivem/build_proot_linux/master/5848-4f71128ee48b07026d6d7229a60ebc5f40f2b9db/fx.tar.xz
說明:我通知GNUAWK行分隔RS符<(空字串,即洗掉它,然后列印并提取href的值。>is-activehref="."https://runtime.fivem.net/artifacts/fivem/build_proot_linux/master
(在 gawk 4.2.1 中測驗)
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/512919.html
標籤:重击文件卷曲wget
上一篇:使用curl除錯HTTP/2會從不同的地方給出不同的回應
下一篇:PHP&Curl-處理XML回應
