首页 > 解决方案 > 如何访问从 Invoke-WebRequest 的响应中获取的 HTML 元素的方法和属性?

问题描述

我有一个 my_table 类的表元素。但是,我似乎无法访问它的任何方法或属性。

请注意:

C:\Work> $table = $res.ParsedHtml.body.getElementsByClassName('my_table')
C:\Work> $table | Get-Member | sls className

IHTMLElementCollection getElementsByClassName (string)
string className () {get} {set}

C:\Work> $table.className
C:\Work> $table | Get-Member | sls getAttribute

Variant getAttribute (string, int)
IHTMLDOMAttribute getAttributeNode (string)
IHTMLDOMAttribute2 getAttributeNodeNS (Variant, string)
Variant getAttributeNS (Variant, string)
Variant ie8_getAttribute (string)
IHTMLDOMAttribute2 ie8_getAttributeNode (string)
Variant ie9_getAttribute (string)
IHTMLDOMAttribute2 ie9_getAttributeNode (string)

C:\Work> $table.getAttributeNode('className')
Method invocation failed because [System.__ComObject] does not contain a method named 'getAttributeNode'.
At line:1 char:1
+ $table.getAttributeNode('className')
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (getAttributeNode:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

C:\Work>

我究竟做错了什么?

标签: htmlpowershelldom

解决方案


推荐阅读