我正在尝试提取网络中 Wifi 接入点的 RSSI 值。唯一可用的解决方案是使用其 IP 地址连接它并尝试读取其状态页面中的值。 在我的研究过程中,我找到了 cURL 库,并编写了一些代码来连接和提取状态页面。但我只有页面的代码,没有我需要获取的值。
因此,我需要您的帮助来找到提取数据值(value)的正确方法。
我的配置:目前是Linux Ubuntu,但SW将在类似树莓派的界面、Eclipse CDT中使用。
我写的代码:
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if (curl)
{
curl_easy_setopt(curl, CURLOPT_USERPWD, "admin:password");
curl_easy_setopt(curl, CURLOPT_URL, "http://192.168.5.179");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
res = curl_easy_perform(curl);
/* Check for errors */
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
/* always cleanup */
curl_easy_cleanup(curl);
}
我需要读取的数据(wlan1_signal):
Signal Strength:</td>
<td >
<div class="style2">
<span id="wlan1_signal">None</span> </div>
</td>
感谢您的帮助。
编辑: 在页面的html代码上,我发现执行了一个脚本来生成动态值:
<script language="javascript" src="js/status.js" type="text/javascript"></script>
在此脚本 ( http://192.168.5.179/en/js/status.js ) 中,我找到了生成 RSSI 值的代码行:
remote_call("get_wifi_info", wlan_devs[index].cdev,
function(data){ ...
$("#wlan"+index+"_signal").html(get_regex(data, /Link Quality=(\S+)/));
...
但我的问题仍然相同:如何读取生成的值?
最佳答案
如果您只需要检索值,而不考虑性能,则可以使用 bash 命令。
curl -s -u admin:password "http://192.168.5.179" | grep -Po '(?<=<span id="wlan1_signal">)[^<]+'
关于c - 使用 cURL 和 C API 通过 http 提取动态数据的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49139329/