解析本地HTML文件 [英] Parse local HTML file
本文介绍了解析本地HTML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以使用PowerShell来解析一个HTML页面
I can use PowerShell to parse an HTML page
PS > $foo = Invoke-WebRequest http://example.com
PS > $foo.Links.Count
1
然而,如果我下载页面
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?
推荐答案
您可以使用
web服务器
来解决Invoke-WebRequest的愚蠢限制
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屋!
查看全文