简体   繁体   English

Casperjs使登录会话保持活动状态

[英]Casperjs keep alive a login session

I'm trying to keep alive a login session, after 3 min of inactivity the user get disconnected. 我正在尝试保持登录会话的状态,在闲置3分钟后,用户断开了连接。

The problem here is that most of cases the page is giving errors 502/504, so I want to send http get request every 20/30 secs without receive a response, just to leave a request and keep alive the session. 这里的问题是,在大多数情况下,页面给出错误502/504,所以我想每20/30秒发送一次http get请求而没有收到响应,只是留下一个请求并保持会话状态。

I want do it but at the same time that I make some stuff on the site, like scrapping, something like a new tab. 我想这样做,但同时我在网站上做了一些事情,例如抓取,例如新建标签。

There's a way to make it works? 有办法使它起作用吗?

It depends on the site's content, but if it has any filter (as in show results filter) you could add a step in the script to change that every 20/30 secs, that means you "refresh" the content and the session stays alive. 它取决于站点的内容,但是如果它具有任何过滤器(如显示结果过滤器),则可以在脚本中添加一个步骤,以每20/30秒更改一次,这意味着您“刷新”了内容并且会话保持活动状态。

Other way is adding a GET parameter on the url, let's say your page is http://www.example.com/infoineed . 另一种方法是在url上添加GET参数,假设您的页面为http://www.example.com/infoineed Add a step using thenOpen('http://www.example.com/infoineed?get=donothing') , this will somehow refresh the page but do nothing. 使用thenOpen('http://www.example.com/infoineed?get=donothing')添加一个步骤,这将以某种方式刷新页面,但不执行任何操作。

And finally you can use reload(),once again, this depends on the site you're working on. 最后,您可以再次使用reload(),这取决于您正在工作的站点。

Hope it helps, cheers! 希望能有所帮助,加油!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM