如何在 PowerShell 中使用 Invoke-WebRequest 獲得網站連結?
要使用 PowerShell 獲取網站上的連結,我們可以首先使用 Invoke-WebRequest cmdlet 從網頁中檢索資料。
$req = Invoke-WebRequest -uri "https://theautomationcode.com" $req
輸出
要僅檢索連結,我們可以使用該屬性,在那裡您還會找到一些子屬性,如 InnerHTML、Innertext、href 等,如輸出所示。
$req = Invoke-WebRequest -uri "https://theautomationcode.com" $req.Links
輸出
innerHTML : Scripts innerText : Scripts outerHTML : <A href="https://theautomationcode.com/scripts/">Scripts</A> outerText : Scripts tagName : A href : https://theautomationcode.com/scripts/
我們只需要連結,所以我們將使用 href 屬性。
$req.Links | Select -ExpandProperty href
輸出
https://theautomationcode.com/2020/11/ https://theautomationcode.com/author/chiragce17/ https://theautomationcode.com/category/powershell/ https://theautomationcode.com/category/troubleshooting/
廣告