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:
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.
Answer
This is getting a bit too long for a comment. What you want to do is possible, in principle, but web servers can be picky about how the request should look. What we can do is to try to provide as much information as possible to help Mathematica make an acceptable request. I would start with this:
req = HTTPRequest[
"https://THEIR_WEB_ADDRESS.com/src/index.php", <|
Method -> "POST",
"Query" -> {"page" -> "login"},
"Body" -> {
"username" -> "fooUser",
"password" -> "fooPassword",
"action" -> "login"
},
"ContentType" -> "application/x-www-form-urlencoded"
|>];
resp = URLRead[req]
The action
parameter comes from the HTML for the form.
It would be interesting to know what resp["StatusCode"]
returns. If it returns OK, it would also be good to check resp["Cookies"]
to see if it returned a cookie. And, of course, you can also check resp["Body"]
to see what they sent back.
Please let me know how it goes.
Comments
Post a Comment