powershell - Parse local HTML file -


I can use PowerShell to parse an HTML page

  PS & gt; $ Foo = Invitation- WebRequest http://example.com Ps & gt; $ Foo.Links.Count 1  

However if I download the page

  PS & gt; Invoke-WebRequest -OutFile example.htm http://example.com  

and then attempt to parse the downloaded page so that it gives unexpected results

How can I parse the local download page?

It appears that come-webReview load file < / Code> Protocol URI is OK, but fails to parse them even in Parscheld 4.0 (where it is officially supported).

An alternative that does not require a website to be installed, it must be directly loaded and parsed in HTML.

  $ html = new object -comobject "HTMLFile"; $ Source = Get-content -Path "file.html" -Rao; $ Html.IHTMLDocument2_write ($ source); $ Html.links.length;  

Note that when I tested it, a single

  & lt; Meta http-equiv = "X-UA-Compatible" content = "IE = edge" / & gt;  

The header stopped my HTML from parsing and I did not know why - the document contained the same XHTML-style header and MSHLL had no problems with those people.


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -