0

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

3 Answers 3

1

You just have to add an appropriate user-agent header.

For example:

$wc = new-object system.net.webclient
$wc.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)")
$wc.DownloadFile("http://whatsmyuseragent.com/","d:\index.html")
Sign up to request clarification or add additional context in comments.

1 Comment

I already tried to specify the User agent, but I get the same error. Is there a way to simulate IE User agent?
1

When trying the webclient Class maybe You're just missing to add a "valid" user Agent

$wc.Headers.Add("user-agent", "Valid WebClient Header")

 

Comments

0

After Googling a little bit I found out how to setup my user agent to get the compatibility with IE.

Final code is 
$wc = new-object system.net.webclient
$wc.Headers.Add("user-agent", "Windows-RSS-Platform/2.0 (MSIE 9.0; Windows NT 6.1)")
$GRSstr = $wc.DownloadString($strGRSpage) 

Many thanks for your help.

Regards, Marco

----- Please mark as answer ------

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.