人妖在线一区,国产日韩欧美一区二区综合在线,国产啪精品视频网站免费,欧美内射深插日本少妇

新聞動(dòng)態(tài)

powershell網(wǎng)絡(luò)蜘蛛解決亂碼問(wèn)題

發(fā)布日期:2022-01-22 00:37 | 文章來(lái)源:CSDN

抓?。ㄅ廊。┚W(wǎng)上信息的腳本程序,俗稱(chēng)網(wǎng)絡(luò)蜘蛛。
powershell中自帶了這樣的兩個(gè)命令,【Invoke-WebRequest】和【Invoke-RestMethod】,但這兩個(gè)命令有時(shí)候會(huì)亂碼。

現(xiàn)在轉(zhuǎn)帖分享, 某個(gè)【歪果仁】寫(xiě)的腳本。來(lái)源于 墻外出處: https://gist.github.com/angel-vladov/9482676

核心代碼

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 傳教士 轉(zhuǎn)帖并修改的文章 2016-01-01, 允許再次轉(zhuǎn)載,但必須保留名字和出處,否則追究法律責(zé)任
}

原文函數(shù)

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 function you can use for reading UTF8 encoded HTML pages content. The built in Invoke-WebRequest and Invoke-RestMethod fail miserably.

版權(quán)聲明:本站文章來(lái)源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來(lái)源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來(lái)源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來(lái),僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。

相關(guān)文章

實(shí)時(shí)開(kāi)通

自選配置、實(shí)時(shí)開(kāi)通

免備案

全球線路精選!

全天候客戶(hù)服務(wù)

7x24全年不間斷在線

專(zhuān)屬顧問(wèn)服務(wù)

1對(duì)1客戶(hù)咨詢(xún)顧問(wèn)

在線
客服

在線客服:7*24小時(shí)在線

客服
熱線

400-630-3752
7*24小時(shí)客服服務(wù)熱線

關(guān)注
微信

關(guān)注官方微信
頂部