为什么cmdlet "Invoke-WebRequest“在某些URL上冻结/挂起?有可能的变通方法吗?我想访问给定网页的"span“对象,如果它不像那样挂起,这个cmdlet将非常有用。
例如,这段代码挂起:
Invoke-WebRequest -Uri "https://cloud.google.com/chrome-enterprise/browser/download/"这不是:
Invoke-WebRequest -Uri "https://www.microsoft.com/fr-ca/"-UseBasicParsing使其运行,但我希望使用Invoke-WebRequest返回的功能,而无需进行基本解析,因为使用基本解析时,我试图提取的span字段不会被填充。
发布于 2019-05-17 23:56:06
这似乎仍然是powershell中的一个bug。
https://github.com/PowerShell/PowerShell/issues/2867
一种可能的解决方法是手动将项目转换为已解析的HTML
Function ConvertTo-NormalHTML {
param([Parameter(Mandatory = $true, ValueFromPipeline = $true)]$HTML)
$NormalHTML = New-Object -Com "HTMLFile"
$NormalHTML.IHTMLDocument2_write($HTML.RawContent)
return $NormalHTML
}
$Content = (Invoke-WebRequest -Uri "https://cloud.google.com/chrome-enterprise/browser/download" -UseBasicParsing ).Content
$ParsedHTML = ConvertTo-NormalHTML -HTML $Content
$ParsedHTMLhttps://stackoverflow.com/questions/56187543
复制相似问题