December 28, 2017 at 4:28 am #90137
I am trying to use the Invoke-WebRequest to be able to login into a website.I am not able to capture contents of homepage i.e after logging in, in Variable $R. I still get the contents of the login page in the variable $R. I have been trying to fix this for many hours and looked at many examples but nothing seems to work. Would someone be able to give me a few pointers? Thanks for the help
$R = Invoke-WebRequest https://portal.concordfax.com/ -SessionVariable FB $Form = $R.Forms $Form.Fields["UserName"] = "XXXXX" $Form.Fields["Password"] = "XXXXX" $R = Invoke-WebRequest -Uri ("https://portal.concordfax.com/Account/LogOn?ReturnUrl=%2f" + $Form.Action) -WebSession $FB -Method POST -Body $Form.Fields $R.links
December 28, 2017 at 12:56 pm #90154
Update: I managed to fix the code by updating line 5 with
$homelanding = Invoke-WebRequest ("https://portal.concordfax.com/Account/LogOn" + $R.ParsedHtml.getElementsByClassName("blueButton login").click) -WebSession $fb -Body $R -Method Post
I am trying to click on a link on the logged in page but it doesnt seem to work i still get the contents of the $homelanding in $output1
$output1 = Invoke-WebRequest ("https://portal.concordfax.com" + $homelanding.links.href.click) -WebSession $fb
I would like to add that the href is relative and not the full path. That is the reason why i am joining them and trying to invoke a Invoke-WebRequest
PS C:\Users\XXXX> $homelanding.links.href /Administration/Accounting
December 28, 2017 at 3:50 pm #90157
Running through a website using Invoke-WebRequest is ***HARD***. You're going to need to start by understanding exactly how that page "logs you in" – ideally using a browser like Chrome or Safari that have good developer tools, so you can see exactly what cookies are being handed back to the browser. Then, you're going to need to compare what's in your $FB variable to that – to make sure you're capturing, and handing back, the same cookie names (the values will obviously differ). You're basically reconstructing a complex part of the browser, and that isn't trivial.
Invoke-WebRequest ("https://portal.concordfax.com" + $homelanding.links.href.click)
That ^^ is probably wrong. You probably just want the href property, not a "click" property, to obtain the relative URL of the link. Double check what that's returning.
December 29, 2017 at 12:55 am #90200
Since you are trying to navigate a GUI, you are going to need a 3rdP tool or 3rdP module for that sort of stuff
Yet, note, much of this is Windows / IE centric tools. So, if you are on another OS/browser, well, you know.
You must be logged in to reply to this topic.