使用Google Apps脚本登录网站

时间:2018-09-25 16:58:55

标签: javascript html google-apps-script

使用Google Apps脚本登录网站已在前面进行了讨论,我很可能已经看到了所有内容并进行了尝试。但是似乎没有任何作用。我必须监督一些事情,感谢您的帮助。

我正在尝试登录此网站https://teslaclub.ch/clubdesk/www?action=login&

看起来相关的登录信息如下:

<form method="post" action="www" accept-charset="UTF-8">
    <input type="hidden" name="action" value="login">
<input type="hidden" name="redirectUrl" value="HxgrZFvkpAK4n-IGMS4gSQ">
<table class="admin">
        <tr>
            <td class="label">Benutzername:</td>
            <td class="field"><input id="userId" name="userId" type="text" value="my login name comes here"></td>
        </tr>
        <tr>
            <td class="label">Passwort:</td>
            <td class="field"><input id="password" name="password" type="password"></td>
        </tr>
        <tr>
            <td class="error" colspan="2"></td>
        </tr>
        <tr>
            <td class="comment" colspan="2" style="line-height: 28px;color:#2eab66;">
                <a href="www?action=signupUser&">
                    Zugang anfordern</a>&nbsp;&nbsp;&nbsp;
                <a href="www?action=recover&">
                    Passwort vergessen</a>/<a href="www?action=changePassword&">
                ändern</a>
                <input style="float: right;" type="submit" value="Anmelden">
            </td>
    </table>
</form>

我正在尝试这样登录(我从其他示例中进行了修改):

function loginToSite(){
  var url = "https://teslaclub.ch/clubdesk/www?action=login&"; //change this.
  var payload = {
    "userId":"my login name comes here", //change this.
    "password":"my password comes here" //and change this. done. no need to enter anything elsewhere.
  }; 
  var opt = {
    "payload":payload,
    "method":"post"
  };
  var response = UrlFetchApp.fetch(url, opt);
  if ( response.getResponseCode() == 200 ) { //could not log in.
    var result = "Couldn't login. Please make sure your username/password is correct.";
  } 
  else if ( response.getResponseCode() == 303 ) { //login was successful. you might receive 302 response code as well depending upon the site. So try changing it to 302.
     var result = "Logged in successfully";
     var cookie = response.getAllHeaders()['Set-Cookie'];     
     var header = {
       'Cookie':cookie[1] //taking the second cookie because when redirected, a new cookie is set. If the page does not redirect, you might need to use cookie[0] here. Try it out yourself!
     };
  }
Logger.log(result);
}

我总是收到200条回复。因此,我认为我缺少“按下”登录(Anmelden)按钮的功能。但是我不确定该怎么做。

我们将非常感谢您的帮助。

亨氏

0 个答案:

没有答案