我正在测试一款通过激活代理来限制网站的软件。似乎有一个错误,代理刚刚停止工作,但只是在网上冲浪大约一两个小时,或者点击数百甚至数千个链接之后。
是否有现有的解决方案可以做到这一点?如果我能以这种方式解决它,我也对编程解决方案感兴趣。
我听说过 firefox 的greasemonkey 插件,但我不熟悉javascript。有没有办法让javascript随机收集页面上的链接,然后随机打开其中一个?
我正在测试一款通过激活代理来限制网站的软件。似乎有一个错误,代理刚刚停止工作,但只是在网上冲浪大约一两个小时,或者点击数百甚至数千个链接之后。
是否有现有的解决方案可以做到这一点?如果我能以这种方式解决它,我也对编程解决方案感兴趣。
我听说过 firefox 的greasemonkey 插件,但我不熟悉javascript。有没有办法让javascript随机收集页面上的链接,然后随机打开其中一个?
Sounds like the proxy might have a session timeout of about an hour (absolute) or about an hour of "no activity".
Leaving aside whether it's a good testing methodology, here's a complete Greasemonkey script that clicks random links:
// ==UserScript==
// @name _YOUR_SCRIPT_NAME
// @include http://YOUR_SERVER.COM/YOUR_PATH/*
// ==/UserScript==
var timeDelaySeconds = 2;
setInterval (clickRandomLink, timeDelaySeconds * 1000);
function clickRandomLink () {
var links = document.querySelectorAll ("a");
/*--- Or fine-tune the links to certain areas or types. EG:
var links = document.querySelectorAll ("#content a");
var links = document.querySelectorAll ("a.comments");
etc.
*/
if (links.length) {
var linkToClick = links[getRandomInt (0, links.length - 1) ];
var clickEvent = document.createEvent ('MouseEvents');
clickEvent.initEvent ('click', true, true);
linkToClick.dispatchEvent (clickEvent);
}
}
function getRandomInt (min, max) {
return Math.floor (Math.random () * (max - min + 1) ) + min;
}
It uses a time-delay to allow for links to AJAX-in. It uses querySelectorAll()
to allow for fine-tuning which links are used, and it sends an actual click event, as that is the most robust way to trigger the most kinds of links.