婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > powershell網(wǎng)絡蜘蛛解決亂碼問題

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

熱門標簽:使用電話機器人電銷是否違法 湖州電銷防封卡 真人和電話機器人對話 什么渠道可以找外呼系統(tǒng)客戶 信陽話務外呼系統(tǒng)怎么收費 金融電銷公司怎么辦理外呼系統(tǒng) 電話智能外呼系統(tǒng)誠信合作 雷霆電話機器人電話 安徽400電話辦理

抓取(爬取)網(wǎng)上信息的腳本程序,俗稱網(wǎng)絡蜘蛛。
powershell中自帶了這樣的兩個命令,【Invoke-WebRequest】和【Invoke-RestMethod】,但這兩個命令有時候會亂碼。

現(xiàn)在轉帖分享, 某個【歪果仁】寫的腳本。來源于 墻外出處: 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 傳教士 轉帖并修改的文章 2016-01-01, 允許再次轉載,但必須保留名字和出處,否則追究法律責任

}

原文函數(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.

標簽:鶴崗 湛江 濟南 德州 山南 六盤水 運城 岳陽

巨人網(wǎng)絡通訊聲明:本文標題《powershell網(wǎng)絡蜘蛛解決亂碼問題》,本文關鍵詞  powershell,網(wǎng)絡,蜘蛛,解決,;如發(fā)現(xiàn)本文內(nèi)容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《powershell網(wǎng)絡蜘蛛解決亂碼問題》相關的同類信息!
  • 本頁收集關于powershell網(wǎng)絡蜘蛛解決亂碼問題的相關信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 青阳县| 十堰市| 宝丰县| 霸州市| 崇文区| 广州市| 寿阳县| 平南县| 通江县| 彰化市| 榆林市| 九龙城区| 营山县| 贵阳市| 岱山县| 武安市| 本溪| 黄冈市| 武宣县| 叶城县| 太仆寺旗| 仁布县| 红桥区| 绍兴市| 扬中市| 阜新| 怀仁县| 五台县| 沙河市| 石屏县| 上蔡县| SHOW| 沧州市| 白河县| 宝丰县| 宾川县| 交城县| 满洲里市| 永登县| 六安市| 新营市|