解析本地 HTML 文件 [英] Parse local HTML file
本文介绍了解析本地 HTML 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以使用 PowerShell 解析 HTML 页面
PS >$foo = Invoke-WebRequest http://example.comPS>$foo.Links.Count1
但是如果我下载页面
PS >Invoke-WebRequest -OutFile example.htm http://example.com
然后尝试解析下载的页面,结果出乎意料
PS >$foo = Invoke-WebRequest file://$pwd/example.htmPS>$foo.Links.Count0
如何解析本地下载的页面?
解决方案
您可以使用带有网络服务器绕过 Invoke-WebRequest 的愚蠢限制
PS >$foo = Invoke-WebRequest http://localhost:8080/example.htmPS>$foo.Links.Count1
注意,即使没有连接,这也能工作,例如
<前>PS > 调用 WebRequest http://example.comInvoke-WebRequest:无法解析远程名称:'example.com'I can use PowerShell to parse an HTML page
PS > $foo = Invoke-WebRequest http://example.com
PS > $foo.Links.Count
1
However if I download the page
PS > Invoke-WebRequest -OutFile example.htm http://example.com
and then try to parse the downloaded page it gives unexpected result
PS > $foo = Invoke-WebRequest file://$pwd/example.htm
PS > $foo.Links.Count
0
How can I parse the local downloaded page?
解决方案
You can use the file with a web server to get around the dumb limitation of Invoke-WebRequest
PS > $foo = Invoke-WebRequest http://localhost:8080/example.htm
PS > $foo.Links.Count
1
Note this will work even with no connection, example
PS > Invoke-WebRequest http://example.com Invoke-WebRequest : The remote name could not be resolved: 'example.com'
这篇关于解析本地 HTML 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文