Powershell Web Scrape Authentication

Hello! I am trying to web scrape discover credit card to automate some tasks I have for my account. I am able to do this on other websites but for some reason discover returns as logged out.

The title is Discover Card: You Are Logged Out

So I don’t get the table for transactions returned.

Here is my code:

$userID = ‘username’
$password = ‘password’

$web = Invoke-WebRequest “`https://portal.discover.com/customersvcs/universalLogin/ac_main” -SessionVariable discoverSession

$form = $web.Forms[1]
$form.Fields[‘userID’] = $userID
$form.Fields[‘password’] = $password

$sess = Invoke-WebRequest -Uri ("`https://card.discover.com/cardmembersvcs/statements/app/activity#/recent" + $form.Action) -WebSession $discoverSession -Method Post -Body $form.Fields

I must be missing something? Thanks for any help!!!

Hi, welcome to the forum :wave:

Firstly, when posting code in the forum, please can you use the preformatted text </> button. It really helps us with readability, and copying and pasting your code (we don’t have to faff about replacing curly quote marks to get things working).

This is impossible to test without an account but I had a quick look at the website and the form data is submitted to
https[:]//portal.discover.com/customersvcs/universalLogin/signin

I wonder if you need to use this as the URI in your second Invoke-WebRequest to authenticate before navigating to the recent activity page?