下载链接后面的文件

下载链接后面的文件

我想编写一个脚本来从 Jetbrains 下载 WEBStorm IDE,然后做进一步的事情。但我无法下载 tar 球。

我正在关注这个,但这并不能解决我的问题。 使用 wget 下载文件

我要下载文件的网页是https://www.jetbrains.com/webstorm/download/download-thanks.html?platform=linux

看起来很简单,但是当我执行 wget 时,我总是得到一个纯 html 页面。通过浏览器地址栏或像 DownThemAll 这样的插件来完成此操作是完全没问题的。

以下是我的命令

wget 'https://www.jetbrains.com/webstorm/download/download-thanks.html?platform=linux' -O WebStorm.tar.gz

我可以从这里下载该文件:

wget https://download.jetbrains.com/webstorm/WebStorm-2017.2.4.tar.gz

但我经过一番挖掘才找到这个网址。有没有办法通过解析“下载”按钮来简单地获取下载文件 url?

是否也可以通过curl来完成?

答案1

此链接适用于最新的 Linux 版本的 WebStorm: https://data.services.jetbrains.com/products/download?code=WS&platform=linux

您可以通过首先调用您想要访问的页面并搜索直接链接来获取此地址:

      $ curl 'https://www.jetbrains.com/webstorm/download/download-thanks.html?platform=linux' | grep "direct link"
      <p class="sub-title no-margin-bottom">Your download should start shortly. If it doesn't, please use the <a id="download-link" href="//data.services.jetbrains.com/products/download?code=WS" data-release-download-link="">direct link</a>.</p>

只需添加 &platfor=your_platform 即可获得最新版本

答案2

我编写了一个简短的脚本,用于安装任何与 Linux 兼容的 JetBrains IDE,包括 WebStorm。您可以找到更多详细信息这里

#!/bin/sh

echo "Installing IntelliJ IDEA..."

# We need root to install
[ $(id -u) != "0" ] && exec sudo "$0" "$@"

# Attempt to install a JDK
# apt-get install openjdk-8-jdk
# add-apt-repository ppa:webupd8team/java && apt-get update && apt-get install oracle-java8-installer

# Prompt for edition
while true; do
    read -p "Enter 'U' for Ultimate or 'C' for Community: " ed 
    case $ed in
        [Uu]* ) ed=U; break;;
        [Cc]* ) ed=C; break;;
    esac
done

# Fetch the most recent version
VERSION=$(wget "https://www.jetbrains.com/intellij-repository/releases" -qO- | grep -P -o -m 1 "(?<=https://www.jetbrains.com/intellij-repository/releases/com/jetbrains/intellij/idea/BUILD/)[^/]+(?=/)")

# Prepend base URL for download
URL="https://download.jetbrains.com/idea/ideaI$ed-$VERSION.tar.gz"

echo $URL

# Truncate filename
FILE=$(basename ${URL})

# Set download directory
DEST=~/Downloads/$FILE

echo "Downloading idea-I$ed-$VERSION to $DEST..."

# Download binary
wget -cO ${DEST} ${URL} --read-timeout=5 --tries=0

echo "Download complete!"

# Set directory name
DIR="/opt/idea-I$ed-$VERSION"

echo "Installing to $DIR"

# Untar file
if mkdir ${DIR}; then
    tar -xzf ${DEST} -C ${DIR} --strip-components=1
fi

# Grab executable folder
BIN="$DIR/bin"

# Add permissions to install directory
chmod -R +rwx ${DIR}

# Set desktop shortcut path
DESK=/usr/share/applications/IDEA.desktop

# Add desktop shortcut
echo "[Desktop Entry]\nEncoding=UTF-8\nName=IntelliJ IDEA\nComment=IntelliJ IDEA\nExec=${BIN}/idea.sh\nIcon=${BIN}/idea.png\nTerminal=false\nStartupNotify=true\nType=Application" -e > ${DESK}

# Create symlink entry
ln -sf ${BIN}/idea.sh /usr/local/bin/idea

echo "Done."

相关内容