Powershell - 将 ASP 页面的源代码分配给变量
也许这是一个愚蠢的问题,但到目前为止我在谷歌中找不到答案。 我需要阅读页面的 HTML 源代码 http://Mysite/ViewRequest.aspx?request_id=xxx。 我已经进行了设置,
wc = new-object -com internetexplorer.application
$wc.visible = $false
$wc.navigate2($strGRSpage).Document
$wc.silent = $true
$wc.visible = $false
$GRSstr = $wc.Document.body.IHTMLElement_outerText
不幸的是,即使我设置了 $wc.silent = $true 和 $wc.visible = $false,也会弹出 IE 页面。 是否有另一种方法(即使使用 HTTP 请求 GET)来检索该数据而不获取 IE 页面。 笔记。该网站 http://Mysite/ViewRequest.aspx?request_id=xxx 仅支持 IE 和 Mozilla。当我尝试使用 Webclient 类时,我总是得到不受支持的浏览器。
在 VBscript 中,以下作品(但我希望在 Powershell 中)
Set oHTML = CreateObject("Microsoft.XMLHTTP")
Set oWeb = CreateObject("InternetExplorer.Application")
oHTML.open "GET" , strGRSpage, false
oHTML.send
strGRStext = oHTML.responseText
非常感谢,
Marco
probably it is a silly question, but I couldn't find the answer in Google so far.
I need to read the HTML source code of a page
http://Mysite/ViewRequest.aspx?request_id=xxx.
I've setup following
wc = new-object -com internetexplorer.application
$wc.visible = $false
$wc.navigate2($strGRSpage).Document
$wc.silent = $true
$wc.visible = $false
$GRSstr = $wc.Document.body.IHTMLElement_outerText
Unfortunately the IE page pops up, even if I set $wc.silent = $true and $wc.visible = $false.
Is there another way (even with HTTP request GET) to retrieve that data without getting the IE page.
NOTE. The site http://Mysite/ViewRequest.aspx?request_id=xxx supports just IE and Mozilla. When I tried to use Webclient Class I get always unsupported browser.
In VBscript following works (but I want it in Powershell)
Set oHTML = CreateObject("Microsoft.XMLHTTP")
Set oWeb = CreateObject("InternetExplorer.Application")
oHTML.open "GET" , strGRSpage, false
oHTML.send
strGRStext = oHTML.responseText
Many thanks,
Marco
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您只需添加适当的
user-agent
标头。例如:
You just have to add an appropriate
user-agent
header.For example:
当尝试 webclient 类时,您可能只是缺少添加“有效”用户代理
$wc.Headers.Add("user-agent", "Valid WebClient Header")
When trying the webclient Class maybe You're just missing to add a "valid" user Agent
$wc.Headers.Add("user-agent", "Valid WebClient Header")
经过一番谷歌搜索后,我发现了如何设置我的用户代理以获得与 IE 的兼容性。
非常感谢您的帮助。
问候,
Marco
----- 请标记为答案 ------
After Googling a little bit I found out how to setup my user agent to get the compatibility with IE.
Many thanks for your help.
Regards,
Marco
----- Please mark as answer ------