ConvertFrom-Html, supplied by the PowerHTML module, turns HTML from a URI or supplied content into a navigable document object. Use that object to select HTML nodes with XPath instead of treating a web page as unstructured text. section 13.3 section 13.3.1
A practical scraping flow builds a search URL, converts its results page, identifies every matching link with a stable XPath, then converts each details page. This accommodates multiple catalog results for one KB article rather than assuming a single match. section 13.3.1
Work with the returned node object by separating page selection from value cleanup:
- Use browser inspection and copied element markup to find attributes that remain consistent across result links; avoid an XPath tied to one changing element ID. section 13.3.1
- Call SelectNodes for repeated elements and SelectSingleNode for a known details container, then read properties such as Id and InnerText. section 13.3.1
- Clean extracted text with Replace, Trim, and Split, or shape link data into custom objects with KB number, title, and ID. section 13.3.1
- Retrieve a details page with Invoke-WebRequest and request headers when needed, then pass the response content to ConvertFrom-Html. section 13.3.1
Find update supersedence
For KB4521858, select all search-result links, remove each link’s _link suffix to form a ScopedViewInline details URL, and convert that page. XPath queries then retrieve architecture, supported products, and superseding-update links; regex extraction can turn those links into KB records. section 13.3.1
$xPath = '//*[' +
'@class="contentTextItemSpacerNoBreakLink" ' +
'and @href="javascript:void(0);"]'
$Search.SelectNodes($xPath) | Format-Table NodeType, Name, Id, InnerText
NodeType Name AttributeCount ChildNodeCount ContentLength InnerText
-------- ---- -------------- -------------- ------------- ---------
Element a 4 1 144 ...
Element a 4 1 148 ...
Element a 4 1 148 ...
This XPath selects every result link sharing the observed class and href attributes, returning nodes whose IDs and text can drive later requests. section 13.3.1
