gpt4 book ai didi

javascript - 使用 powershell Invoke-WebRequest 获取 div 的属性

转载 作者:行者123 更新时间:2023-11-30 21:13:46 24 4
gpt4 key购买 nike

我想使用 powershell 使用 Invoke-WebRequest 从 html 中获取 Example2 但这不起作用电源外壳:

$html = Invoke-WebRequest -Uri "https://example.com"
$link = $html.ParsedHtml.getElementsByClassName("Example1")['0'].getAttribute("Example2)
$Reply = Invoke-WebRequest -Uri $link
Write-Host $Reply

html:

<div class="Example1" Example2="https://example.com/example" b="1" a="1"</div>

我希望它写入主机 https://example.com/example

最佳答案

你的基本上是正确的只是一些错误

A) 不要在索引周围加上引号。差['0'],好[0]

B) 你在 .getAttribute("Example2) 中缺少双引号应该是 .getAttribute("Example2")

$html = Invoke-WebRequest -Uri "https://developer.mozilla.org/en-US/docs/Web/HTML"
$link = $html.ParsedHtml.getElementsByClassName("external")[0].getAttribute("href")
Invoke-WebRequest -Uri $link

关于javascript - 使用 powershell Invoke-WebRequest 获取 div 的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45882178/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com