I am converting some ruby scripts to posh:
> gem install nokogiri
> irb
> require 'nokogiri'
> $html = Nokogiri::HTML("<div><img src='//127.0.0.1:5598/user/first.png' />
<img src='//127.0.0.1:5598/user/second.png' /></div>")
> $html.xpath('//img[contains(@src,"first")]')
# Output: <img src='//127.0.0.1:5598/user/first.png' />
In PowerShell, I have:
> [System.Reflection.Assembly]::LoadWithPartialName("System.Xml.Linq")
> [System.Reflection.Assembly]::LoadWithPartialName("System.Xml.XPath")
> $html = [System.Xml.Linq.XDocument]::Parse("<div>
<img src='//127.0.0.1:5598/user/first.png' />
<img src='//127.0.0.1:5598/user/second.png' /></div>")
> [System.Xml.XPath.Extensions]::XPathSelectElement($html,
'//img[contains(@src,"first")]')
# It displays the properties of XElement type object
How to get the same output?
Is there a better way parsing html in PowerShell v.4?