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.

5 Responses

  1. Brent May 12, 2016 / 9:32 pm

    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.

  2. Ryan March 7, 2018 / 5:08 am

    This looks pretty cool! I just recently heard about Google Scripts and have been looking into using them. This code seems like maybe it could do something that I’m looking at doing, but I haven’t been able to get it to work. I am, admittedly, very much a beginner at these things. I’m trying to pull data from a table that exists on a website, but I need to log in to the website before I can access that section. I get either a 302 or 303 response code and the logged in successful in the logger, but it returns something like:

    Object moved
    Object moved to here.

    Any ideas on what that is telling me? Thanks in advance.

  3. Kristian March 22, 2018 / 8:25 am

    I like this concept. Could you please share sample to link that google script with html template login form?

  4. Sudhakar May 31, 2018 / 3:44 pm

    We have prepared a dashboard for our on going project and from the dashboard Iam collecting data from different tables and saving it to google spread sheet by using IMPORTHTML as per my flexibility.But due to some issues we have protected dashboard with user name and password. After that iam unable to fetch the data from dashboard.can you help me out with any solution to get the data to spreadsheets with username and password credentials.


Leave a Reply

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