5

I have a CSHTML file which has a block <script type="text/javascript"></script> inside.

It will show usernames:

for (var i = 0; i < result2.Users.length; i++) {
    var item = "<li style='width:100%;'>" + result2.Users[i].TchatEngineId.toString() + " | " + result2.Users[i].Pseudo + "</li>";

Now I want to get this result in Powershell, anyone knows how to do it?

I tried with Invoke-RestMethod and Invoke-WebRequest, but it always returns the source code HTML and not the result.

1 Answer 1

2

you could try to automate with the internet explorer COM object.

function wait4IE($ie=$global:ie){
    while ($ie.busy -or $ie.readystate -lt 4){start-sleep -milliseconds 200}
}


$global:ie=new-object -com "internetexplorer.application"
$ie.visible=$true
$ie.navigate("http://domain.com/file.html")
wait4IE

$names=$ie.Document.getElementsByTagName("li")
$names|%{$_.innerText} 
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks. I tried this and it actually works. But I need to put this script to my server for monitoring and it'll run every second, I don't want to use ie because it takes too much resource.
don't make ie visible and don't forget to quit ie $ie.quit() at the end of the script, this shall not consume so much ressource.... every seconds seems a bit too much (time taken to start ie, open url and parse page....)
I'm figuring how to do this directly by JavaScript, if there exists some way to get my JS variables in Shell.
Does this mean if I want to automate the web application, which depends on JavaScript extensively, using PowerShell, then the only option (other than IE COM Object) is to use PowerShell+Selineum+Chrome WebDrive? I tried using Invoke-WebRequest but the response has JavaScript which is needed to continue loading the website. Any feedback on this please?

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.