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
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.
“Clicking” a link this way is also hard. It would be best to (a) login, (b) capture the cookies handed back, (c) figure out what URL you want next, and (d) directly request that URL, rather than “clicking” a link. It does seem like you’re trying to do that… but, if what you’re meaning to “click” is actually running client-side JavaScript, you’re hosed, because Invoke-WebRequest can’t “run” JavaScript. It’s not a browser. So you’ll need ti inspect the page and see if that link is JUST a URL, or if it’s also wired up to some client-side JavaScript.
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.