簡體   English   中英

如何從鏈接中獲取特定值? 電源外殼

[英]How to get a specific value from a link? Powershell

假設我有一個鏈接 - https://chromedriver.storage.googleapis.com/LATEST_RELEASE我可以在其中獲取最新的 Chrome 發布版本。 我需要檢索此值 (101.0.4951.41) 並將其寫入變量。 例如,我創建變量

$LatestChromeRelease = https://chromedriver.storage.googleapis.com/LATEST_RELEASE

所以這個變量的值是'101.0.4951.41'

我可以在我的進一步行動中使用它。

請告知如何在 PowerShell 腳本中實現它。 謝謝!

$LatestChromeRelease = (wget https://chromedriver.storage.googleapis.com/LATEST_RELEASE).Content

由於給定的端點只返回版本而不返回任何其他內容,這只是發送 Web 請求的問題:

$response = Invoke-WebRequest -Uri 'https://chromedriver.storage.googleapis.com/LATEST_RELEASE' -UseBasicParsing
$version = if($response.StatusCode -eq 200){ $response.Content }

如果請求成功, $version現在保存字符串值"101.0.4951.41" (或任何當前最新版本號)

使用Invoke-WebRequest

function Get-LatestChromeReleaseVersion{
    $Response = Invoke-WebRequest -URI https://chromedriver.storage.googleapis.com/LATEST_RELEASE
    return $Response.Content    
}

$LatestChromeRelease = Get-LatestChromeReleaseVersion

Write-Host "LatestChromeRelease:"  $LatestChromeRelease

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM