我想将网站保留为离线对象。我在 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/
#offline 分析在本地保存网站并使用 get-content 导入(不起作用)
#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
#offline 分析将网站本地保存为 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.
有谁知道如何在本地存储网站并稍后恢复 [Microsoft.PowerShell.Commands.HtmlWebResponseObject] 对象以进行进一步处理?