function Read-HtmlPage {
param ([Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)][String] $Uri)
function Read-HtmlPage {
param ([Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)][String] $Uri)
# Invoke-WebRequest and Invoke-RestMethod can’t work properly with UTF-8 Response so we need to do things this way.
[Net.HttpWebRequest]$WebRequest=[Net.WebRequest]::Create($Uri)
[Net.HttpWebResponse]$WebResponse=$WebRequest.GetResponse()
$Reader=New-Object IO.StreamReader($WebResponse.GetResponseStream())
$Response=$Reader.ReadToEnd()
$Reader.Close()
# Create the document class
[mshtml.HTMLDocumentClass] $Doc=New-Object -com “HTMLFILE”
$Doc.IHTMLDocument2_write($Response)
# Returns a HTMLDocumentClass instance just like Invoke-WebRequest ParsedHtml
$Doc
#powershell 传教士 转帖并修改的文章 2016-01-01, 允许再次转载,但必须保留名字和出处,否则追究法律责任
}
© 版权声明
文章版权归作者所有,未经允许请勿转载。