这听起来很简单,但是文档并未完全说明具体方式。
尝试抓取需要用户登录才能获取所需信息的页面。
我可以接受使用请求或请求承诺的基本请求。
主页上有一个登录框,如下所示:
<form method="post" id="frmlogin" name="frmlogin" class="form-horizontal" role="form">
<input type="hidden" name="token" id="login_token" value="6861b13edb5d626abe48b405476207bc" />
<p class="toFormLoginSpace">
<label for="flTitleFile" class="formloginLabel">Email:</label>
<input type="text" name="customers_email_address_login" id="customers_email_address_login" class="formloginField" maxlength="50">
</p><br clear="all" />
<p class="toFormLoginSpace">
<label for="flTitleFile" class="formloginLabel">Password:</label>
<input type="password" name="customers_password_login" id="customers_password_login" class="formloginField" maxlength="50">
</p><br clear="all" />
<div style="float:left;width: 60%">
<a href="/lost_password.php" class="purpleLink11">Forgot your password?</a>
<br />
<a href="/register.php" class="purpleLink11">Apply for an account</a>
</div>
<div style="float:right;width: 38%">
<button name="btnlogin" id="btnlogin" class="btn btn-primary pull-right md-margin-left-10" type="submit">
Login <i class="fa fa-arrow-right"></i>
</button>
</div>
<br clear="all" /><br clear="all" />
</form>
我可以使用cheerio查看此表单,并请求或请求Promise。
该网站似乎不允许您使用http://username:password@thedomain.com
登录该网站在php上运行,但正在使用jQuery
ive尝试按照文档向auth部分提出请求,如下所示:
request.get('https://www.thedomain.co.uk/', {
'auth': {
'user': 'username',
'pass': 'Password',
'sendImmediately': false
}
},function(err,response,data){
console.log(err)
console.log(response)
console.log(data)
});
作为回报,我只是返回首页而没有登录,因为登录表单仍然显示。在请求文档中有关于Cookie的简短信息,但没有很多。
所以最后一个问题是“你怎么做”
我查看了以下内容: Node JS request-promise for PUT with auth How can I scrape sites that require authentication using node.js? https request basic authentication node.js https://github.com/request/request https://blog.risingstack.com/node-hero-node-js-request-module-tutorial/ How to automatically login to the site using url parameters?及更多