Skip to content

How to login to a website via Google Script?

Whenever I have to accomplish something these days (in terms of programming that is), the language that I turn to at first is Google Script. I have gotten so used to it, and its interface that I prefer it over any other language, or services. The added bonus of using it is that you can run the script regularly by setting up a timer. No need to meddle with cronjobs and what-not on your server.

Some time back, I was trying to login to my college's LMS (Learning Management System) using Google Script. My college uses Moodle and it has been setup such that if you do not login for 12 consecutive days, your account will get disabled. Once disabled, you need to go to the authority and bend over your backwards to convince him to re-active your account. I don't login to Moodle very often and neither do my friends. I turned to Google Script to solve this problem, to login to Moodle every week.

You can use the following script to login to any (I hope) website via Google Script.

See the logger to know whether your login was successful. Obviously, you need to replace "enter your username" et cetera with your username and so on. Read the comments as well. Though the code is simple, I got stuck in the cookie part. I was using cookie[0] and it would not redirect me to the next page. So, keep that in mind.

Good luck and do subscribe below.

Published inHow To's

2 Comments

  1. Brent Brent

    I have been trying for weeks to use a script to login to a website and import a table, but haven't had any luck. It appears that your script is logging me in, but I can't seem to get the cookies sent back to the server with the get command. I had to add a piece after your script for the cookies. Is there any way you could help me figure out what I'm doing wrong? I'd really appreciate the help.

Leave a Reply

Your email address will not be published. Required fields are marked *