我正在尝试登录一个网站,以便从其中获取数据并将其导入到Google文档电子表格中。我已经阅读了这里的各种帖子,但是我无法确定需要发送哪些数据。
该网站的登录页面有一个带有以下字段的表单。
我尝试了以下脚本,但sessionDetails总是返回"Undefined"。
该网站的登录页面有一个带有以下字段的表单。
<form action="https://fantasyfootball.telegraph.co.uk/premierleague/log-in/" method="post" id='reg-form'>
<fieldset class='login'>
<div class="required">
<label for="email">Email:</label>
<input type="text" name="email" id="email" class="input-text" size="10" maxlength="50" value="my.name@address.com" />
</div>
<div class="required">
<label for="pass">Password:</label>
<input type="password" name="pass" id="pass" class="input-password" size="10" maxlength="15" value="some-password" />
</div>
</fieldset>
<div id="remember-me-container">
<input type="checkbox" checked="checked" id="remember-me" name="remember-me" value="remember-me" />
<label for="remember-me" id="remember-lbl">Remember me</label>
</div>
<input type="submit" id="submit-btn" value="Login" name='Submit' class='btn'/>
</form>
我尝试了以下脚本,但sessionDetails总是返回"Undefined"。
// Returns the html of the page.
function sGetPage (sUrl) {
var url = "https://fantasyfootball.telegraph.co.uk/premierleague/log-in/";
// logging in, following https://dev59.com/u2Ei5IYBdhLWcg3wIJFH
var payload =
{
"email" : "ian.shaw@iee.org",
"pass" : "asdf123",
"submit-btn": "Login",
"remember-me" : "remember-me"
};
var options =
{
"method" : "post",
"payload" : payload,
"followRedirects" : false
};
var login = UrlFetchApp.fetch( url, options);
var sessionDetails = login.getAllHeaders()['Set-Cookie'];
Logger.log(sessionDetails);
var response = UrlFetchApp.fetch ("https://fantasyfootball.telegraph.co.uk/premierleague/leagues/view/8000912/4015677/", {"headers" : {"Cookie" : sessionDetails} });
var sHtml = response.getContentText();
Logger.log(sHtml);
}
有什么建议将不胜感激。