从包含Javascript的调制解调器网页中提取数据以用于Rainmeter的更好方法



美好的一天,

简短版本:寻找一种方法,以适合 Rainmeter 在屏幕上显示的格式从调制解调器概述 LAN 页面上运行的 javascript 中获取数据。

长版本:所以,我有一个华为LTE调制解调器,其服务与巧克力茶壶一样可靠。因此,我在第二个屏幕上不断打开带有 Firefox 页面的调制解调器概述页面,它每 5 秒左右自动刷新一次,但信号细节很小 - 如果我放大页面,它们不适合页面。

最近我开始研究Rainmeter和Web解析器仪表。但是,它有一个限制,即它不适用于javascript。

然后,我偶然发现了PhantomJS,并惊人地设法将代码组合在一起,将页面写入HTML文件,然后由Rainmeter解析。我每 8 秒从 Rainmeter 调用一次 PhantomJS 命令行。在大多数情况下,它可以工作,但是当 HTML 文件的重新加载/写入同时发生时,Rainmeter 正在尝试访问该文件时会绊倒 - 这可能很容易解决。

我的代码:

var fs = require('fs');
var page = require('webpage').create();
page.open('http://192.168.254.254/html/overview.html', function (status) {
if (status !== "success") {
console.log('Unable to load the address!');
phantom.exit();
} else {
window.setTimeout(function () {
fs.write('page.html', page.content, 'w');
phantom.exit();
}, 1000);
}
});

我注意到,当使用 Firefox 打开页面时,网络中使用的带宽非常少(使用显示吞吐量的图表(,但是通过我实现的 PhantomJS 和 Rainmeter,每次加载/刷新页面时

,带宽都会激增。所以我对此的看法:

  1. 从我读到的内容来看,PhantomJS已经死了,所以切换到其他东西是可以的,但我喜欢PhantomJS的地方是它是一个单行.exe命令,可以在Rainmeter中使用。

  2. 如果我可以在页面上加载 Javascript 中的值而不刷新整个页面,我认为它会更好。

感谢您的阅读。

编辑:

以为我会从调制解调器粘贴相关的页面源,所以更清楚我想要什么

首先是页面 HTML:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="csrf_token" content="3NawXult26b2eh87zvVkvEGYEZ5roIU1">
<meta name="csrf_token" content="ok2fUOoZjv8702fth7vMYJjAzIOZaFEN">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<link type="text/css" rel="stylesheet" href="../css/main.css" />
<script type="text/javascript" src="../lib/libjquery.js"></script>
<script type="text/javascript" src="../js/changelang.js"></script>
<script type="text/javascript" src="../js/format.js"></script>
<script type="text/javascript" src="../js/main.js"></script>
<script type="text/javascript" src="../js/redirect.js"></script>
<script type="text/javascript" src="../js/validation.js"></script>
<script type="text/javascript" src="../js/overview.js"></script>
<title></title>
</head>
<body>
<div id="all_content" class="body_bg">
<div class="">
<div class="">
<div id="header" class="header"></div>
</div>
<div class="content overview">
<div id="internet_status">
<p></p>
<h2>
<span>
<script type="text/javascript">
dw(IDS_internet_status);
</script>
</span>
</h2>
<div class="cut_off_rule"></div>
<table id="internet_status_table" cellpadding="0px" cellspacing="0px">
<tr>
<td width="256px" height="32px">
<script type="text/javascript">
dw(IDS_usim_card_status + common_colon);
</script>
</td>
<td>
<span id="internet_usim_card_status"></span>
</td>
</tr>
<tr>
<td width="256px" height="32px">
<script type="text/javascript">
dw(IDS_network_status + common_colon);
</script>
</td>
<td>
<span id="internet_network_status"></span>
</td>
</tr>
<tr>
<td width="256px" height="32px">
<script type="text/javascript">
dw(IDS_ipv4_status + common_colon);
</script>
</td>
<td>
<span id="internet_ipv4_status"></span>
</td>
</tr>
</table>
</div>
<div id="mobile_network">
<p></p>
<h2>
<span>
<script type="text/javascript">
dw(IDS_mobile_network);
</script>
</span>
</h2>
<div class="cut_off_rule"></div>
<table id="mobile_network_table" cellpadding="0px" cellspacing="0px">
<tr>
<td width="256px" height="32px">
<script type="text/javascript">
dw(common_label_total + common_colon);
</script>
</td>
<td>
<span id="mobile_total"></span>
</td>
</tr>
<tr>
<td width="256px" height="32px">
<script type="text/javascript">
dw(sd_label_upload + common_colon);
</script>
</td>
<td>
<span id="mobile_sent"></span>
</td>
</tr>
<tr>
<td width="256px" height="32px">
<script type="text/javascript">
dw(down_label_download + common_colon);
</script>
</td>
<td>
<span id="mobile_received"></span>
</td>
</tr>
<tr>
<td width="256px" height="32px">
<script type="text/javascript">
dw(IDS_uplink_rate + common_colon);
</script>
</td>
<td>
<span id="mobile_uplink_rate"></span>
</td>
</tr>
<tr>
<td width="256px" height="32px">
<script type="text/javascript">
dw(IDS_downlink_rate + common_colon);
</script>
</td>
<td>
<span id="mobile_downlink_rate"></span>
</td>
</tr>
<tr>
<td width="256px" height="32px">
<script type="text/javascript">
dw(dialup_label_duration + common_colon);
</script>
</td>
<td>
<span id="mobile_duration"></span>
</td>
</tr>
</table>
</div>
<div id="wireless_status">
<p></p>
<h2>
<span>
<script type="text/javascript">
dw(IDS_wireless_status);
</script>
</span>
</h2>
<div class="cut_off_rule"></div>
<table id="wireless_status_table" cellpadding="0px" cellspacing="0px">
<tr>
<td width="256px" height="32px">
<script type="text/javascript">
dw(IDS_device_info_plmn + common_colon);
</script>
</td>
<td>
<span id="device_wireless_plmn"></span>
</td>
</tr>
<tr>
<td width="256px" height="32px">
<script type="text/javascript">
dw(IDS_service_status + common_colon);
</script>
</td>
<td>
<span id="device_wireless_service"></span>
</td>
</tr>
<tr>
<td width="256px" height="32px">
<script type="text/javascript">
dw(IDS_system_label_rsrq + common_colon);
</script>
</td>
<td>
<span id="device_wireless_rsrq"></span>
</td>
</tr>
<tr>
<td width="256px" height="32px">
<script type="text/javascript">
dw(IDS_system_label_rsrp + common_colon);
</script>
</td>
<td>
<span id="device_wireless_rsrp"></span>
</td>
</tr>
<tr>
<td width="256px" height="32px">
<script type="text/javascript">
dw(IDS_system_label_rssi + common_colon);
</script>
</td>
<td>
<span id="device_wireless_rssi"></span>
</td>
</tr>
<tr>
<td width="256px" height="32px">
<script type="text/javascript">
dw(IDS_system_label_sinr + common_colon);
</script>
</td>
<td>
<span id="device_wireless_sinr"></span>
</td>
</tr>
<tr>
<td width="256px" height="32px">
<script type="text/javascript">
dw(IDS_system_label_pci + common_colon);
</script>
</td>
<td>
<span id="device_wireless_pci"></span>
</td>
</tr>
<tr>
<td width="256px" height="32px">
<script type="text/javascript">
dw(IDS_system_label_cell_id + common_colon);
</script>
</td>
<td>
<span id="device_wireless_cell_id"></span>
</td>
</tr>
<tr>
<td width="256px" height="32px">
<script type="text/javascript">
dw(IDS_roaming_status + common_colon);
</script>
</td>
<td>
<span id="device_wireless_roaming"></span>
</td>
</tr>
</table>
</div>
<div id="lan_wlan_status">
<p></p>
<h2>
<span>
<script type="text/javascript">
dw(IDS_lan_wlan_status);
</script>
</span>
</h2>
<div class="cut_off_rule"></div>
<table id="lan_wlan_status_table" cellpadding="0px" cellspacing="0px">
<tr>
<td width="256px" height="32px">
<script type="text/javascript">
dw(IDS_current_lan + common_colon);
</script>
</td>
<td>
<span id="current_lan_user"></span>
</td>
</tr>
<tr>
<td width="256px" height="32px">
<script type="text/javascript">
dw(IDS_current_wlan + common_colon);
</script>
</td>
<td>
<span id="current_wlan_user"></span>
</td>
</tr>
</table>
</div>
<div id="antenna_status">
<p></p>
<h2>
<span>
<script type="text/javascript">
dw(IDS_antenna_status);
</script>
</span>
</h2>
<div class="cut_off_rule"></div>
<table id="antenna_status_table" cellpadding="0px" cellspacing="0px">
<tr>
<td width="256px" height="32px">
<script type="text/javascript">
dw(IDS_antenna1 + common_colon);
</script>
</td>
<td>
<span id="antenna1_status"></span>
</td>
</tr>
<tr>
<td width="256px" height="32px">
<script type="text/javascript">
dw(IDS_antenna2 + common_colon);
</script>
</td>
<td>
<span id="antenna2_status"></span>
</td>
</tr>
</table>
</div>
</div>
</div>
<div id="footer" class="footer">
</div>
</div>
</div>
<noscript>
<div class="noscript_text">
Your browser does not support JavaScript.
</div>
</noscript>
</body>
</html>

以及相关的概述.js我在包含设备信号值的函数getWirelessStatus之后

var loopTime = 6000;
function padLeft(str, lenght) {
if (str.length >= lenght) {
return str;
} else {
return padLeft('0' + str, lenght);
}
}
function trafficStatus_volume(project_id, trafficXml) {
if (trafficXml >= g_monitoring_dumeter_tb) {
$("#" + project_id).text(formatFloat(parseFloat(trafficXml) / g_monitoring_dumeter_tb, 2) + " " + common_unit_tb);
} else if (trafficXml >= g_monitoring_dumeter_gb) {
$("#" + project_id).text(formatFloat(parseFloat(trafficXml) / g_monitoring_dumeter_gb, 2) + " " + common_unit_gb);
} else if (trafficXml >= g_monitoring_dumeter_mb) {
$("#" + project_id).text(formatFloat(parseFloat(trafficXml) / g_monitoring_dumeter_mb, 2) + " " + common_unit_mb);
} else if (trafficXml >= g_monitoring_dumeter_kb) {
$("#" + project_id).text(formatFloat(parseFloat(trafficXml) / g_monitoring_dumeter_kb, 2) + " " + common_unit_kb);
} else if (trafficXml < g_monitoring_dumeter_kb) {
$("#" + project_id).text(formatFloat(parseFloat(trafficXml), 2) + " " + common_unit_byte);
}
}
function trafficStatus_rate(project_id, trafficXml) {
if (trafficXml >= g_monitoring_dumeter_tb) {
$("#" + project_id).text(formatFloat(parseFloat(trafficXml) / g_monitoring_dumeter_tb, 2) + " " + common_unit_tbps);
} else if (trafficXml >= g_monitoring_dumeter_gb) {
$("#" + project_id).text(formatFloat(parseFloat(trafficXml) / g_monitoring_dumeter_gb, 2) + " " + common_unit_gbps);
} else if (trafficXml >= g_monitoring_dumeter_mb) {
$("#" + project_id).text(formatFloat(parseFloat(trafficXml) / g_monitoring_dumeter_mb, 2) + " " + common_unit_mbps);
} else if (trafficXml >= g_monitoring_dumeter_kb) {
$("#" + project_id).text(formatFloat(parseFloat(trafficXml) / g_monitoring_dumeter_kb, 2) + " " + common_unit_kbps);
} else if (trafficXml < g_monitoring_dumeter_kb) {
$("#" + project_id).text(formatFloat(parseFloat(trafficXml), 2) + " " + common_unit_byteps);
}
}
function getInternetStatus() {
getAjaxData('api/pin/status', function ($xml) {
var ret = xml2object($xml);
var simStatusText = IDS_usim_card_normal;
var simStatus = ret.response.SimState;
if (ret.type == 'response') {
if (simStatus === '260') {
simStatusText = dialup_label_pin_code_required;
} else if (simStatus === '261') {
if (ret.response.SimPukTimes == '0') {
simStatusText = dialup_help_puk_locked;
} else {
simStatusText = dialup_label_puk_code_required;
}
} else if (g_net_mode === dialup_label_no_service && (simStatus == '0' || simStatus == '255')) {
simStatusText = dialup_label_sim_invalid;
} else if (simStatus == 'undefined') {
simStatusText = dialup_label_sim_invalid;
} else {
getAjaxData('api/pin/simlock', function ($xml) {
var ret = xml2object($xml);
if (ret.response.SimLockEnable == '1') {
simStatusText = dialup_label_sim_invalid;
}
}, {
sync: true
});
}
}
$('#internet_usim_card_status').text(simStatusText);
});
$('#internet_network_status').text(g_net_mode);
if ('900' === G_MonitoringStatus.response.ConnectionStatus) {
$("#internet_ipv4_status").text(dialup_label_connecting);
} else if ('901' == G_MonitoringStatus.response.ConnectionStatus) {
$("#internet_ipv4_status").text(dialup_label_connected);
} else if ('903' == G_MonitoringStatus.response.ConnectionStatus) {
$("#internet_ipv4_status").text(dialup_label_disconnecting);
} else {
$("#internet_ipv4_status").text(dialup_label_disconnected);
}
}
function getNetworkData() {
if (g_module.wifioffload_enable && G_StationStatus != null && WIFI_CONNECTED == G_MonitoringStatus.response.WifiConnectionStatus) {
trafficStatus_volume('mobile_total', parseFloat(G_StationStatus.response.TotalTxFlux) + parseFloat(G_StationStatus.response.TotalRxFlux));
trafficStatus_volume('mobile_sent', G_StationStatus.response.TotalTxFlux);
trafficStatus_volume('mobile_received', G_StationStatus.response.TotalRxFlux);
trafficStatus_rate('mobile_uplink_rate', G_StationStatus.response.TxFlux);
trafficStatus_rate('mobile_downlink_rate', G_StationStatus.response.RxRate);
$('#mobile_duration').text(getCurrentTime(G_StationStatus.response.TotalTime));
} else {
getAjaxData('api/monitoring/traffic-statistics', function ($xml) {
var ret = xml2object($xml);
if (ret.type == 'response') {
networkData = ret.response;
if (G_MonitoringStatus == null || MACRO_CONNECTION_CONNECTED != G_MonitoringStatus.response.ConnectionStatus) {
networkData.CurrentConnectTime = 0;
networkData.CurrentDownload = 0;
networkData.CurrentUpload = 0;
}
trafficStatus_volume('mobile_total', parseFloat(networkData.TotalUpload) + parseFloat(networkData.TotalDownload));
trafficStatus_volume('mobile_sent', networkData.TotalUpload);
trafficStatus_volume('mobile_received', networkData.TotalDownload);
trafficStatus_rate('mobile_uplink_rate', networkData.CurrentUploadRate);
trafficStatus_rate('mobile_downlink_rate', networkData.CurrentDownloadRate);
$('#mobile_duration').text(getCurrentTime(networkData.TotalConnectTime));
}
});
}
}
function getWirelessStatus() {
getAjaxData('api/device/signal', function ($xml) {
var ret = xml2object($xml);
if ('response' == ret.type) {
var signalObj = ret.response;
$('#device_wireless_plmn').text(signalObj.plmn ? signalObj.plmn : common_na);
$('#device_wireless_rsrq').text(signalObj.rsrq ? signalObj.rsrq : common_na);
$('#device_wireless_rsrp').text(signalObj.rsrp ? signalObj.rsrp : common_na);
$('#device_wireless_rssi').text(signalObj.rssi ? signalObj.rssi : common_na);
$('#device_wireless_sinr').html(signalObj.sinr ? signalObj.sinr : common_na);
$('#device_wireless_pci').text(signalObj.pci ? signalObj.pci : common_na);
if (!isNaN(signalObj.cell_id)) {
var baseStationID = signalObj.cell_id >>> 8;
var logicCellID = signalObj.cell_id & 0xFF;
var strBaseStationID = Number(baseStationID).toString(10);
var strlogicCellID = Number(logicCellID).toString(10);
strBaseStationID = padLeft(strBaseStationID, 7);
strlogicCellID = padLeft(strlogicCellID, 3);
signalObj.format_cell_id = strBaseStationID + ' - ' + strlogicCellID;
} else {
signalObj.format_cell_id = signalObj.cell_id;
}
$('#device_wireless_cell_id').text(signalObj.cell_id != '' ? signalObj.format_cell_id : common_na);
$('#device_wireless_roaming').text(G_MonitoringStatus.response.RoamingStatus == 0 ? common_no : common_yes);
}
});
if (G_MonitoringStatus.response) {
switch (parseInt(G_MonitoringStatus.response.ServiceStatus)) {
case 0:
$("#device_wireless_service").text(dialup_label_no_service);
break;
case 1:
if (G_MonitoringStatus.response.SimStatus == '255') {
$("#device_wireless_service").text(dialup_label_no_service);
} else {
$("#device_wireless_service").text(diagnosis_wireless_status_service_status1);
}
break;
case 2:
$("#device_wireless_service").text(diagnosis_wireless_status_service_status2);
break;
case 3:
$("#device_wireless_service").text(diagnosis_wireless_status_service_status3);
break;
case 4:
$("#device_wireless_service").text(diagnosis_wireless_status_service_status4);
break;
default:
$("#device_wireless_service").text(dialup_label_no_service);
break;
}
}
}
function getCurrentUser() {
getAjaxData('api/lan/HostInfo', function ($xml) {
var ret = xml2object($xml);
if (ret.type == 'response') {
if (ret.type == 'response') {
var hostList = CreateArray(ret.response.Hosts.Host);
var lanCount = 0;
var wlanCount = 0;
for (host in hostList) {
if (hostList[host].InterfaceType === 'Ethernet') {
if (hostList[host].Active == '1') {
lanCount++;
}
} else {
if (hostList[host].Active == '1') {
wlanCount++;
}
}
}
$("#current_lan_user").text(lanCount);
}
}
});
$('#current_wlan_user').text(G_MonitoringStatus.response.CurrentWifiUser);
}
function getAntennaStatus() {
getAjaxData('api/device/antenna_type', function ($xml) {
var ret = xml2object($xml);
if (ret.type == 'response') {
antennaStatus = ret.response;
$("#antenna1_status").text(antennaStatus.antenna1type == 1 ? IDS_antenna_outside : IDS_antenna_interior);
$("#antenna2_status").text(antennaStatus.antenna2type == 1 ? IDS_antenna_outside : IDS_antenna_interior);
}
});
}
function getUserLv() {
getAjaxData('api/user/state-login', function ($xml) {
var ret = xml2object($xml);
if (ret.type === 'response' && ret.response.State == '0') {
if (g_default_password_status == 0) {
gotoPageWithoutHistory("modifypassword.html");
} else {
gotoPageWithHistory('home.html');
}
}
}, {
sync: true
});
}
getUserLv()
$(document).ready(function () {
var loopFun = function () {
getInternetStatus();
getNetworkData();
getWirelessStatus();
getCurrentUser();
getAntennaStatus();
setTimeout(loopFun, loopTime);
}
loopFun();
});

谢谢

感谢@Anuga现在能够自己使用 Rainmeter - 只是发布了相关代码以获取答案。

相关内容

  • 没有找到相关文章

最新更新