We’d like to remind Forumites to please avoid political debate on the Forum.
This is to keep it a safe and useful space for MoneySaving discussions. Threads that are – or become – political in nature may be removed in line with the Forum’s rules. Thank you for your understanding.
📨 Have you signed up to the Forum's new Email Digest yet? Get a selection of trending threads sent straight to your inbox daily, weekly or monthly!
The Forum now has a brand new text editor, adding a bunch of handy features to use when creating posts. Read more in our how-to guide
Anyone know Java/Google script?
IronWolf
Posts: 6,462 Forumite
in Techie Stuff
I'm trying to write a simple bit of script in Google sheets that will log into a website for me and grab the cookie from the header, but it isn't working. Is there anyone that knows the language and what could be wrong?
var payload =
{
"user_login" : "free",
"user_pass" : "password",
};
var options =
{
"method" : "post",
"payload" : payload,
"followRedirects" : false
};
var login = UrlFetchApp.fetch("https://example.com/wp-login.php" , options);
var sessionDetails = login.getAllHeaders()['Set-Cookie'];
Faith, hope, charity, these three; but the greatest of these is charity.
0
Comments
-
Which bit isn't working? The log in or getting the cookie?0
-
Which bit isn't working? The log in or getting the cookie?
The login
I found some better code specifically for wordpress, but still not workingvar options = { "method": "post", "payload": { "log": "free", "pwd": "password", "wp-submit": "Login" }, "followRedirects": false }; var login = UrlFetchApp.fetch("http://example.com/wp-login.php" , options); var text = login.getContentText(); Logger.log(text); var cookie = login.getAllHeaders()['Set-Cookie']; Logger.log(cookie);
The webpage output is just the login form and cookie doesn't exist.
I've tried it without redirects=false as well and still the same problem.Faith, hope, charity, these three; but the greatest of these is charity.0 -
you're missing a comma but I can't see where exactly.just in case you need to know:
HWTHMBO - He Who Thinks He Must Be Obeyed (gained a promotion, we got Civil Partnered Thank you Steinfeld and Keidan)
DS#1 - my twenty-five-year old son
DS#2 - my twenty -one son0 -
fannyadams wrote: »you're missing a comma but I can't see where exactly.
How do you know that's the problem?
I've looked through and can't see anywhere that a comma is missing :SFaith, hope, charity, these three; but the greatest of these is charity.0 -
Nevermind, I found an alternate solution using basic authentication if anyone is interested
http://stackoverflow.com/questions/23546255/how-to-use-urlfetchapp-with-credentials-google-scripts
The cookies thing just never seemed to workFaith, hope, charity, these three; but the greatest of these is charity.0 -
This method has a bit more code for working with cookies
http://stackoverflow.com/questions/19567105/how-to-fetch-a-wordpress-admin-page-using-google-apps-script0
This discussion has been closed.
Confirm your email address to Create Threads and Reply
Categories
- All Categories
- 353.5K Banking & Borrowing
- 254.2K Reduce Debt & Boost Income
- 455.1K Spending & Discounts
- 246.6K Work, Benefits & Business
- 602.9K Mortgages, Homes & Bills
- 178.1K Life & Family
- 260.6K Travel & Transport
- 1.5M Hobbies & Leisure
- 16K Discuss & Feedback
- 37.7K Read-Only Boards
