0
votes

Website I am attempting to do this on: https://www.netvendor.net/login

I am trying to login to the website automatically and kick off a script to create users in bulk for us.

If you run an Invoke-WebRequest on this page, it returns information, but nothing about the forms. They are simply not displayed. However, if you view the page source or inspect element, there are clearly forms on the page and they are not composed of JS or anything else that would mess it up. How can I get PowerShell to recognize these fields? I am using the following command:

Invoke-WebRequest -Uri "www.netvendor.net/login" -Method GET -UseBasicParsing

Because of the issue above, I decided I would just POST the information I needed by examining the request. The request requires three things:

  • email
  • password
  • _token

Unfortunately, the token is randomly generated each time a browser session is initiated. If you view source on the page and search for "_token", you will get the parameter that is needed. It doesn't seem like there is any way to retrieve this from the page? I am a bit lost as to what I can do at this point, especially since there is no API or anything else for me to work with.

1
Is there any specific reason you're using the UseBasicParsing switch? The forms property populates without it.Jesse
@Jesse I figured out that this is actually an issue with my particular computer, as I was unable to get any output without using that flag. You are correct, on a clean machine that flag is unnecessary.Brendan Lovett

1 Answers

0
votes

For all interested, here is the final working script:

$nvlogin = Invoke-WebRequest "https://www.netvendor.net/login" -SessionVariable "netvendor"
$nvtoken = $nvlogin.InputFields.Where({ $_.Name -eq "_token" })[0].Value

$nvbody = @{ 
    "_token" = $nvtoken
    "email" = "[email protected]"
    "password" = 'credentials'
}

Invoke-WebRequest -Uri "https://www.netvendor.net/login" -WebSession $netvendor -Method 'POST' -Body $nvbody