我想使用 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/