如何在 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/

更新时间:2021 年 1 月 18 日

4K+ 浏览次数

开启你的 职业之旅

完成课程,取得证书

开始学习
广告
© . All rights reserved.