gpt4 book ai didi

html - 如何使用 grease-monkey 重复加载网页并检查元素?

转载 作者:行者123 更新时间:2023-11-28 20:33:54 24 4
gpt4 key购买 nike

基本上,我想重复加载一个 URL,比如 http://xyz.co.in然后检查特定元素的值,就像测试过程一样并监视该流的服务器日志。

我试图通过重复访问同一主机来进行进一步处理来模拟一部分生产流量。我怎样才能最好地解决这个问题?

加载网页 -> 监控服务器日志 -> 在前端监控某些元素值 -> 再次重复。

最佳答案

Greasemonkey 不是 load testing 的最佳工具网页/服务器/应用程序。

但是这里有一个重复加载页面并检查元素的脚本:

// ==UserScript==
// @include http://xyz.co.in/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
// ==/UserScript==

$(document).ready (Greasemonkey_main);

function Greasemonkey_main ()
{
do
{
var TargetNode = $("#TargetNode"); //-- Look for node with id, "TargetNode".

if (TargetNode && TargetNode.length)
{
//--- Maybe also check contents:
if (/Node contents to search for/i.test (TargetNode.text () ) )
{
alert ("We found what we're looking for");
break;
}
}

//--- Failsafe check on number of reloads
var NumReloads = parseInt (document.location.search.replace (/.*num_gm_reloads=(\d+).*/, "$1") )
if (NumReloads > 2)
{
alert ("After 2 reloads, we still didn't find what we were looking for.");
break;
}

//--- We neither found the stop code nor exhausted our retries, so reload the page.
if (NumReloads)
NumReloads++;
else
NumReloads = 1;

var TargetURL = window.location.href;
//--- Strip old URL param, if any. Note that it will always be at the end.
TargetURL = TargetURL.replace ( /(.*?)(?:\?|&)?num_gm_reloads=\d+(.*)/, "$1$2" );
var ParamSep = /\?/.test (TargetURL) ? "&" : "?";

TargetURL = TargetURL + ParamSep + 'num_gm_reloads=' + NumReloads;

window.location.href = TargetURL; //-- Reload the page.

} while (0)
}

关于html - 如何使用 grease-monkey 重复加载网页并检查元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4778586/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com