0

Web サイトをオブジェクトとしてオフラインで保存したい。Windows10でPowershell 5.1.19041.546を使用しています

#オンライン分析 (機能します)

$website = Invoke-WebRequest https://www.w3schools.com/html/html_tables.asp
$website | gm

#I get an  Microsoft.PowerShell.Commands.HtmlWebResponseObject object
#next I use $website in this function (I call it Get-WebRequestTable) that expects a [Microsoft.PowerShell.Commands.HtmlWebResponseObject] $WebRequest, input object https://www.leeholmes.com/blog/2015/01/05/extracting-tables-from-powershells-invoke-webrequest/

Web サイトをローカルに保存し、get-content でインポートする #offline 分析 (機能しません)

#saving the website locally
Invoke-WebRequest -Uri  https://www.w3schools.com/html/html_tables.asp -OutFile C:\temp\website
#writing the website back to a variable
$offlinedata = Get-Content C:\temp\website
#I get a string object
$offlinedata | gm
#String can not be used in function :Get-WebRequestTable : Cannot process argument transformation on parameter 'WebRequest'. Cannot convert the "System.Object[]" value of type "System.Object[]" to type "Microsoft.PowerShell.Commands.HtmlWebResponseObject".
Get-WebRequestTable -WebRequest $offlinedata

Web サイトを XML としてローカルに保存する #オフライン分析 (機能しません)

Invoke-WebRequest -Uri  https://www.w3schools.com/html/html_tables.asp  | Export-Clixml C:\temp\website.xml

これは非常に長く実行され、次の XML を取得します (省略)

<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04">
  [...]                  <S>System.__ComObject</S>
                         <S>System.__ComObject</S>

この時点で無限ループになりそう

 <S>System.__ComObject</S>

#json に変換してローカルに保存 (動作しません)

$website = Invoke-WebRequest -Uri  https://www.w3schools.com/html/html_tables.asp 
$website | ConvertTo-Json

私は得る

ConvertTo-Json : An item with the same key has already been added.

Web サイトをローカルに保存し、後で [Microsoft.PowerShell.Commands.HtmlWebResponseObject] オブジェクトを復元してさらに処理する方法を知っている人はいますか?

4

1 に答える 1