javascript - 使用 Google Apps 脚本登录网站
问题描述
使用 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>
<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)按钮的功能。但我不确定我该怎么做。
您的帮助将不胜感激。
亨氏
解决方案
推荐阅读
- ionic-framework - Ionic iOS输入字段隐藏在键盘后面
- mysql - Mysql更新用户余额SQL语法错误
- c++ - 我正在尝试在 Arduino 中制作一个对象但出现错误
- aws-lambda - Cloudwatch 日志过滤器触发 lambda,然后从日志数据中提取值
- windows - Robocopy 批处理脚本不断重启
- spring-boot - 了解多模块项目中的 Spring Boot Maven 插件
- javascript - 如何将电子文件从“require”转换为“import”以与 TypeScript 一起使用?角2+
- node.js - 关于visual studio代码的方法建议
- sql-server - 无法转换字段数据类型
- database - 交易对手在意外时间发送会话拒绝消息,并显示消息无法建立会话