</p> <p>This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. </p> <p>If you did not receive a copy of the PHP license, or have any questions about PHP licensing, please contact license@php.net. </p> </td></tr> </table> </div></body></html>这一段是html语言吗?为什么请求网页后编写title = etree.xpath('/html/body/div[1]/div[1]/div[2]/ul/li/a/text()')会是一个空列表(在 xpath helper下可以输出结果)
时间: 2024-04-06 10:07:10 浏览: 360
不完全是HTML语言,它包含HTML标签和一些文本内容。这段代码是PHP的许可证声明。
至于你的第二个问题,可能是因为你的XPath表达式没有匹配到任何内容。你可以尝试使用Chrome浏览器的开发者工具,在Elements标签下查看网页的DOM结构,确认XPath表达式的正确性。另外,也可以尝试使用相对路径或更简洁的XPath表达式来匹配元素。
相关问题
/* * Copyright (C) 2011-2014 MediaTek Inc. * * This program is free software: you can redistribute it and/or modify it under the terms of the * GNU General Public License version 2 as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. * If not, see <http://www.gnu.org/licenses/>. */ #include <linux/module.h> #include <linux/list.h> #include <linux/spinlock.h> #include "SCP_power_monitor.h" #include "scp_helper.h" static LIST_HEAD(power_monitor_list); static DEFINE_SPINLOCK(pm_lock); static atomic_t power_status = ATOMIC_INIT(SENSOR_POWER_DOWN); void scp_power_monitor_notify(uint8_t action, void *data) { struct scp_power_monitor *c; unsigned long flags; spin_lock_irqsave(&pm_lock, flags); list_for_each_entry(c, &power_monitor_list, list) { WARN_ON(c->notifier_call == NULL); c->notifier_call(action, data); pr_debug("scp_power_monitor_notify, module name:%s notify\n", c->name); } switch (action) { case SENSOR_POWER_DOWN: atomic_set(&power_status, SENSOR_POWER_DOWN); break; case SENSOR_POWER_UP: atomic_set(&power_status, SENSOR_POWER_UP); break; } spin_unlock_irqrestore(&pm_lock, flags); } int scp_power_monitor_register(struct scp_power_monitor *monitor) { int err = 0; struct scp_power_monitor *c; WARN_ON(monitor->name == NULL || monitor->notifier_call == NULL); spin_lock_irq(&pm_lock); list_for_each_entry(c, &power_monitor_list, list) { if (!strcmp(c->name, monitor->name)) { err = -1; goto out; } } list_add(&monitor->list, &power_monitor_list); if (atomic_read(&power_status) == SENSOR_POWER_UP) { pr_debug("scp_power_monitor_notify, module name:%s notify\n", monitor->name); monitor->notifier_call(SENSOR_POWER_UP, NULL); } spin_unlock_irq(&pm_lock); return err; out: pr_err("%s scp_power_monitor_register fail\n", monitor->name); spin_unlock_irq(&pm_lock); return err; } int scp_power_monitor_deregister(struct scp_power_monitor *monitor) { if (WARN_ON(list_empty(&monitor->list))) return -1; spin_lock_irq(&pm_lock); list_del(&monitor->list); spin_unlock_irq(&pm_lock); return 0; }分析代码
这段代码是一个基于 Linux 内核的电源监控模块,主要包含以下几个部分:
1. 头文件引入和宏定义:包括了一些必要的头文件和宏定义,如模块、链表、自旋锁等。
2. 结构体定义:定义了一个名为 scp_power_monitor 的结构体,包含了模块名称、通知回调函数等信息。
3. 全局变量定义:定义了一个名为 power_monitor_list 的链表和一个名为 power_status 的原子变量,分别用于存储已注册的电源监控模块和当前电源状态。
4. scp_power_monitor_notify 函数:用于通知所有已注册的电源监控模块有关电源状态的改变,通过遍历链表来调用每个模块的通知回调函数来实现。同时,根据 action 参数来更新 power_status 变量的值。
5. scp_power_monitor_register 函数:用于注册电源监控模块,将其添加到 power_monitor_list 链表中。如果已经存在同名模块,则返回错误;否则添加到链表中,并且如果当前电源状态为 SENSOR_POWER_UP,则调用该模块的通知回调函数来提醒其电源已经打开。
6. scp_power_monitor_deregister 函数:用于注销电源监控模块,从 power_monitor_list 链表中删除该模块的信息。
总体来说,这段代码实现了一个简单的电源监控模块,在需要监控电源状态的场景下可以作为一个可靠的工具使用。
以下代码是什么意思/* * sonic-server Sonic Cloud Real Machine Platform. * Copyright (C) 2022 SonicCloudOrg * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package org.cloud.sonic.gateway.config; import com.alibaba.fastjson.JSONObject; import org.cloud.sonic.common.http.RespEnum; import org.cloud.sonic.common.http.RespModel; import org.cloud.sonic.common.tools.JWTTokenTool; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.cloud.gateway.filter.GatewayFilterChain; import org.springframework.cloud.gateway.filter.GlobalFilter; import org.springframework.core.Ordered; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.http.server.reactive.ServerHttpResponse; import org.springframework.stereotype.Component; import org.springframework.web.server.ServerWebExchange; import reactor.core.publisher.Mono; import java.nio.charset.StandardCharsets; import java.util.List; @Component public class AuthFilter implements GlobalFilter, Ordered { @Value("${filter.white-list}") private List<String> whiteList; @Autowired private JWTTokenTool jwtTokenTool; @Override public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) { for (String white : whiteList) { if (exchange.getRequest().getURI().getPath().contains(white)) { return chain.filter(exchange); } } String token = exchange.getRequest().getHeaders().getFirst("SonicToken"); ServerHttpResponse response = exchange.getResponse(); response.getHeaders().add("Content-Type", "text/plain;charset=UTF-8"); DataBuffer buffer = sendResp(response); if (token == null) { return response.writeWith(Mono.just(buffer)); } // verify token if (!jwtTokenTool.verify(token)) { return response.writeWith(Mono.just(buffer)); } return chain.filter(exchange); } @Override public int getOrder() { return -100; } private DataBuffer sendResp(ServerHttpResponse response) { JSONObject result = (JSONObject) JSONObject.toJSON(new RespModel(RespEnum.UNAUTHORIZED)); DataBuffer buffer = response.bufferFactory().wrap(result.toJSONString().getBytes(StandardCharsets.UTF_8)); return buffer; } }
这段代码是一个Spring Cloud Gateway中的全局过滤器,用于对请求进行身份认证和授权处理。代码中包含以下主要内容:
1. 声明了一个名为AuthFilter的组件,并实现了GlobalFilter和Ordered接口。
2. 通过@Autowired注解注入了JWTTokenTool类的实例和通过@Value注解注入了白名单列表。
3. 实现了filter方法,该方法会在每个请求到达网关时被调用。
4. 首先,根据白名单列表判断当前请求是否在白名单内,如果是,则直接放行。
5. 如果不在白名单内,则尝试从请求头中获取名为"SonicToken"的token。
6. 创建一个ServerHttpResponse对象用于返回响应,并设置Content-Type为"text/plain;charset=UTF-8"。
7. 如果没有获取到token,则返回未授权的响应。
8. 如果获取到了token,则使用JWTTokenTool类对token进行验证,如果验证失败,则返回未授权的响应。
9. 如果验证通过,则继续执行后续的过滤器链。
10. 实现了getOrder方法,用于指定过滤器的执行顺序,返回-100表示该过滤器具有最高优先级。
11. 实现了sendResp方法,用于构建未授权响应的内容。
总体来说,这段代码实现了对请求进行身份认证和授权的功能,并根据配置的白名单进行特殊处理。如果请求没有经过认证或授权,将返回未授权的响应。
阅读全文