One of my students is doing summer research for a local company to help analyze some of their data. Trouble is, the web interface they provide for downloading the data only allows one to download one customer's info at a time; there are over 3000 customers to analyze.
I'd like to use Mathematica (MMA) to automate this process. Step 1: use MMA to log in to their website. I've looked at many similar posts and still struggle to understand how to use Import
or URLFetch
or URLExecute
to accomplish this.
I can't share the company's URL, though from the page source this seems to be the relevant code:
<div class="container">
<form class="form-signin" role="form" action="index.php?page=login" method="POST">
<h2 class="form-signin-heading">Please sign in</h2>
<input type="text" name="username" class="form-control" placeholder="Username" required autofocus>
<input type="password" name="password" class="form-control" placeholder="Password" required>
<input type="hidden" name="action" value="login" />
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
</form>
</div>
I tried using
URLExecute["https://THEIR_WEB_ADDRESS.com/src/index.php?page=admin", {"username" -> "fooUser", "password" -> "fooPassword"}]
but the response seems to indicate the website doesn't understand the requested page. I also tried variations of "Username" vs "username", etc., to no avail.
Can someone point me in the right direction based on the page source? I know you won't be able to test your own answer as the actual URL is not given.
index.php?page=login
, not?page=admin
. This will return a cookie, which Mathematica will store away in the variable$Cookies
and use for further requests. So when you next runURLRead["https://THEIR_WEB_ADDRESS.com/src/index.php?page=admin"]
then that cookie is used to identify you, there's no need to supply username and password to that request. There are many things that can go wrong, but in principle, this is how it should work. $\endgroup$login
vsadmin
part. Still doesn't work; same result. Guess this falls into the "many things that can go wrong" part. Your hands are certainly tied in that I'm giving incomplete info on the url, etc. $\endgroup$