在间隔时使用正则表达式提取字符串html

时间:2022-06-02 00:17:38

There is a public website with this in the source:

在源代码中有一个公共网站:

</div><script type="text/rocketscript">
function calculateIndexIncome() {
    var khs = $('#t9').val();
    var btcusd = $('#t9_1').val();
    var btckhs = $('#t9_2').val();
    var dayprofitperkhs = 0.00000018188885404454654
    var arr = btcusd.split(' ');
    btcusd = arr[0];

    var totalinvestmentusd = ((khs * btckhs) * btcusd).toFixed(2);
    var totalinvestmentbtc = (khs * btckhs).toFixed(8);
    var dailyincomebtc = (khs * dayprofitperkhs).toFixed(8);
    var dailyincomeusd = ((khs * dayprofitperkhs) * btcusd).toFixed(2);
    var monthlyincomebtc = (dailyincomebtc * 31).toFixed(8);
    var monthlyincomeusd = (dailyincomeusd * 31).toFixed(2);
    var breakevendays = (totalinvestmentusd / dailyincomeusd).toFixed(0);
    var monthlypercentage = ((100 / breakevendays) * 30).toFixed(2);

    $('#tl').html('Total KHS: ' + khs + '<br/>Total Investment: ' + totalinvestmentbtc + ' BTC ($' + totalinvestmentusd + ' USD)<br/><br/>Daily Income: ' + dailyincomebtc + ' BTC ($' + dailyincomeusd + ' USD)<br/>Monthly Income: ' + monthlyincomebtc + ' BTC ($' + monthlyincomeusd + ' USD)<br/><br/>Break Even In: ' + breakevendays + ' Days.<br/><br/>Monthly Rate: ' + monthlypercentage + '%');
}

I need to be able to extract two values: btckhs and dayprofitperkhs. if I look at page source, dayprofitperkhs is different everytime I refresh.

我需要能够提取两个值:btckhs和dayprofitperkhs。如果我查看页面源,每次刷新时dayprofitperkhs都不同。

Edit:

Jimmy Chandra came up with this bookmarklet:

Jimmy Chandra想出了这个书签:

javascript:
setInterval(logging,60000);
w1 = window.open("https://scrypt.cc/index.php");
function logging(){
console.log (w1.$('#t9_2').val());
var re=/var\s*dayprofitperkhs\s*=\s*([0-9\.]+)\s*/gi;
var matches=re.exec(document.body.innerHTML);
console.log(RegExp.$1);
w1.location.href = 'https://scrypt.cc/index.php';
}

This works ALMOST perfectly. it gets the dayprofitperkhs, but only on the first interval. After that, the value is no longer updated, although t9_2 IS updated...

这几乎完美地工作。它得到了dayprofitperkhs,但只在第一个间隔。之后,虽然t9_2已更新,但不再更新该值...

Anyone?

3 个解决方案

#1


I don't know where that site is, so I am just running this against this SO question, but the following bookmarklet is getting me what I want...

我不知道那个网站在哪里,所以我只是针对这个问题运行这个,但是下面的书签让我想要的东西......

As I mentioned in the comment, I use Regular Expression against the document body inner html and I am looking for dayprofitperkhs and capturing the numbers and decimal separator on the right side of the equal sign. Also trying to compensate for any extra spaces in between (\s*). RegExp.$1 gave me the number that I am looking for.

正如我在评论中提到的,我对文档正文内部html使用正则表达式,我正在寻找dayprofitperkhs并捕获等号右侧的数字和小数点分隔符。还试图弥补其间的任何额外空格(\ s *)。 RegExp。$ 1给了我正在寻找的号码。

javascript:(function(){var re=/var\s*dayprofitperkhs\s*=\s*([0-9\.]+)\s*/gi;var matches=re.exec(document.body.innerHTML);console.log(RegExp.$1);}());

So your final bookmarklet should be something like:

所以你的最终书签应该是这样的:

javascript:
setInterval(logging,60000);
w1 = window.open("siteurl.com");
function logging(){
console.log (w1.$('#t9_2').val());
var re=/var\s*dayprofitperkhs\s*=\s*([0-9\.]+)\s*/gi;
var matches=re.exec(w1.document.body.innerHTML);
console.log(RegExp.$1);
w1.location.href = 'siteurl.com';
}

#2


The variables in question are local variables within the calculateIndexIncome() function, so no, you can't access them from outside that function.

有问题的变量是calculateIndexIncome()函数中的局部变量,所以不,你不能从该函数外部访问它们。

The reason the first one "works" is because you're not referring to the variable, but rather the value: $('#t9_2').val(). This is a jquery selector which finds the element with the ID t9_2 and grabs its value.

第一个“工作”的原因是因为你没有提到变量,而是值:$('#t9_2')。val()。这是一个jquery选择器,它查找ID为t9_2的元素并获取其值。

#3


You cannot visit it because its a local variable, it only exists in calculateIndexIncome() function.

你不能访问它,因为它是一个局部变量,它只存在于calculateIndexIncome()函数中。

By the way, you needn't open a new window to visit the variables. You can use chrome dev tools to directly modify the javascript to print the values, or set a breakpoint to debug the code.

顺便说一句,您无需打开新窗口来访问变量。您可以使用chrome dev工具直接修改javascript以打印值,或设置断点来调试代码。

Here is a tutorial for chrome dev tools: https://www.codeschool.com/courses/discover-devtools

以下是chrome dev工具的教程:https://www.codeschool.com/courses/discover-devtools

#1


I don't know where that site is, so I am just running this against this SO question, but the following bookmarklet is getting me what I want...

我不知道那个网站在哪里,所以我只是针对这个问题运行这个,但是下面的书签让我想要的东西......

As I mentioned in the comment, I use Regular Expression against the document body inner html and I am looking for dayprofitperkhs and capturing the numbers and decimal separator on the right side of the equal sign. Also trying to compensate for any extra spaces in between (\s*). RegExp.$1 gave me the number that I am looking for.

正如我在评论中提到的,我对文档正文内部html使用正则表达式,我正在寻找dayprofitperkhs并捕获等号右侧的数字和小数点分隔符。还试图弥补其间的任何额外空格(\ s *)。 RegExp。$ 1给了我正在寻找的号码。

javascript:(function(){var re=/var\s*dayprofitperkhs\s*=\s*([0-9\.]+)\s*/gi;var matches=re.exec(document.body.innerHTML);console.log(RegExp.$1);}());

So your final bookmarklet should be something like:

所以你的最终书签应该是这样的:

javascript:
setInterval(logging,60000);
w1 = window.open("siteurl.com");
function logging(){
console.log (w1.$('#t9_2').val());
var re=/var\s*dayprofitperkhs\s*=\s*([0-9\.]+)\s*/gi;
var matches=re.exec(w1.document.body.innerHTML);
console.log(RegExp.$1);
w1.location.href = 'siteurl.com';
}

#2


The variables in question are local variables within the calculateIndexIncome() function, so no, you can't access them from outside that function.

有问题的变量是calculateIndexIncome()函数中的局部变量,所以不,你不能从该函数外部访问它们。

The reason the first one "works" is because you're not referring to the variable, but rather the value: $('#t9_2').val(). This is a jquery selector which finds the element with the ID t9_2 and grabs its value.

第一个“工作”的原因是因为你没有提到变量,而是值:$('#t9_2')。val()。这是一个jquery选择器,它查找ID为t9_2的元素并获取其值。

#3


You cannot visit it because its a local variable, it only exists in calculateIndexIncome() function.

你不能访问它,因为它是一个局部变量,它只存在于calculateIndexIncome()函数中。

By the way, you needn't open a new window to visit the variables. You can use chrome dev tools to directly modify the javascript to print the values, or set a breakpoint to debug the code.

顺便说一句,您无需打开新窗口来访问变量。您可以使用chrome dev工具直接修改javascript以打印值,或设置断点来调试代码。

Here is a tutorial for chrome dev tools: https://www.codeschool.com/courses/discover-devtools

以下是chrome dev工具的教程:https://www.codeschool.com/courses/discover-devtools