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

标签 javascript html powershell

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

相关文章:

python - WSL——未找到命令

javascript - ESLint 和 Prettier 冲突,无法为代码块禁用 Prettier

javascript - 用匿名函数替换普通函数

javascript - ReactJS TypeError : _this3. state.Objects.map 不是函数

html - 只要我的 html 页面上内容的高度为 %100,我怎样才能使我的边栏?

windows - 进程 block 在 Graphics.DrawString 中不起作用

javascript - 使用 JavaScript 获取变量的 TagName 值

javascript - 从背景颜色列表中选择并为每个元素应用不同的颜色

Javascript/jQuery - 解析返回 'data' 作为 HTML 以供进一步选择?

powershell - 如何使用PowerShell递归搜索目录中的所有文件,包括隐藏目录中的隐藏文件?