【发布时间】:2018-05-15 07:21:12
【问题描述】:
所以我试图从网站上获取一些文本,一旦我尝试使用 ParsedHtml 返回一个对象,powershell 就会停止响应(即使我让它在后台运行几分钟,它也不会再做任何事情了)。 这可能是什么原因?
PS P:\> $url = "mywebsite"
PS P:\> $result = invoke-WebRequest $url
PS P:\> $result | Get-Member
TypeName: Microsoft.PowerShell.Commands.HtmlWebResponseObject
Name MemberType Definition
---- ---------- ----------
Dispose Method void Dispose(), void IDisposable.Dispose()
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
AllElements Property
Microsoft.PowerShell.Commands.WebCmdletElementCollection AllElements {get;}
BaseResponse Property System.Net.WebResponse BaseResponse {get;set;}
Content Property string Content {get;}
Forms Property
Microsoft.PowerShell.Commands.FormObjectCollection Forms {get;}
Headers Property
System.Collections.Generic.Dictionary[string,string] Headers {get;}
Images Property
Microsoft.PowerShell.Commands.WebCmdletElementCollection Images {get;}
InputFields Property
Microsoft.PowerShell.Commands.WebCmdletElementCollection InputFields {get;}
Links Property
Microsoft.PowerShell.Commands.WebCmdletElementCollection Links {get;}
ParsedHtml Property mshtml.IHTMLDocument2 ParsedHtml {get;}
RawContent Property string RawContent {get;set;}
RawContentLength Property long RawContentLength {get;}
RawContentStream Property System.IO.MemoryStream RawContentStream {get;}
Scripts Property
Microsoft.PowerShell.Commands.WebCmdletElementCollection Scripts {get;}
StatusCode Property int StatusCode {get;}
StatusDescription Property string StatusDescription {get;}
PS P:\> $result.ParsedHtml | Get-Member
然后程序在最后一个命令后冻结。 弹出一个弹出窗口,询问我是否允许在我的电脑上保存 cookie,但单击是或否都无济于事。 这可能是什么原因?
$result.RawContent
例如可以正常工作并打印出所有 html 文本,但没有 getelementsby-Method,我猜它在 ParsedHtml 中,因此我需要它..它适用于例如 youtube,但适用于特定站点我想检查它是否冻结。 非常感谢任何帮助!
【问题讨论】:
-
尝试在您的
Invoke-WebRequest通话中添加-UseBasicParsing开关。 -
刚试了下,$result 中已经没有 ParsedHtml 了。尝试访问 $result.ParsedHtml 时出现丢失对象错误,当我使用 $result | 时也不会出现不再使用 Get-Member 方法
-
相信这是由 Internet Explorer 中的安全设置引起的。当它解析 HTML 时,它使用 IE,以及它的安全设置。
-
我现在尝试解决。还有其他方法可以从网站上的表格中提取特定单词吗?
-
@btc 找到解决方案了吗?
标签: html powershell