当前位置:网站首页>爬虫笔记之xpath
爬虫笔记之xpath
2022-04-22 06:09:00 【刀刀777999】
xpath如何取包含多个class属性
如果HTML结构是这样
<div class="demo"></div>
那么我知道可以写xpath //div[@class="demo"]
但是如果我的html是
<div class="test demo"></div>
<div class="demo test"></div>
<div class="test demo2"></div>
我只想选出有demo这个class的对象,那应该怎么弄
要取多个class属性值的元素,应该如何办呢;
如:
<div class='a b'>test</div>
如果是用xpath('//div[@class="a"]')会取不到这里面的值;
可以用如下的表达式:
xpath('//div[contains(@class,"a")]')
它会取得所有class为a的元素
或者
xpath('//div[contains(@class,"a") and contains(@class,"b")]')
它会取class同时有a和b的元素
and改为or,就是选择class=a或者class=b的元素
如果没记错的话可以这么来:
//div[contains(@class, 'demo')]
如果是多个则可以:
//div[contains(@class, 'demo') and contains(@class, 'other')]
如果目标 class 不一定是第一个,那么:
//div[contains(concat(' ', @class, ' '), 'demo')]
原文链接
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
版权声明
本文为[刀刀777999]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_44192799/article/details/121682472
边栏推荐
- Analysis of running process of stm32wb55 Bluetooth protocol stack
- stm32wb55 基于rtt的ble sample制作过程
- 数字IC设计和CS选那个?
- Quantify PM2 5 data
- DP to HDMI scheme | cs5216 Scheme Application | cs5216 design scheme
- STM32 learning record 0004 - ISP serial port download
- RT-Thread 传感器软件包归类
- Remote program upgrade scheme of transparent cloud gateway in construction machinery under epidemic environment
- Application of can optical transceiver in fire water monitor
- 环网冗余CAN光端机在保得威尔消防火灾报警系统中的应用
猜你喜欢

芯片设计怎样准备即将面临的秋季补招和来年的春招?

DP转HDMI方案|CS5216方案应用|CS5216设计方案

STM32学习记录——开发环境安装

转IC设计需要补充哪方面的知识技能?

STM32 learning record - development environment installation

Ag9310mcq supports the design reference circuit of mother seat forward and reverse plug typec to HDMI projection scheme

Sss1700 qfn36 single chip designs a USB typec headset | supports the automatic switching of USB headset scheme between wire control and European and American regulations

MATLAB:女声转男声

SQL学习记录

数字IC设计自学入门难吗?如何快速入门呢?
随机推荐
Alternative ag9311 design circuit | cs5266 application circuit diagram | design and development of three in one scheme of typec docking station
IDEA debug调试教程
LwIP 1.4.1 Chinese annotation source code
FreeRTOS v10. 1.0 source code Chinese annotation version
leetcode598:范围求和II
Application of ring network redundant can optical transceiver in Baldwin fire alarm system
Td041s485h is fully compatible with iso3080, iso3086, iso3082 and iso3088
数字IC设计,学完verilog语法,还需要学习什么?
I've gone too far, but I can't get out of the routine of ddrx debugging
集成电路模拟版图入门-版图基础学习笔记(三)
LCFNET系列CAN转光纤以太网设备实现CAN网络之间超远距离光纤连通
CAN光端机在消防水炮中的应用
PL2586设计电路|PL2586替代FE1.1S电路图|USB2.0HUB工业级集线器方案设计
CAN总线中继网桥在新能源测试系统中的应用。
Why not recommend tin spraying process for high-speed PCB with crimping devices
Ag9310mcq supports the design reference circuit of mother seat forward and reverse plug typec to HDMI projection scheme
Quantify the relationship between 911 calls and years from 2015 to 2017
STM32 learning record 0004 - ISP serial port download
HDMI切换器方案|3进1出HDMI切换器|5进1出HDMI2.0切换器AG7111设计电路
数字IC设计自学入门难吗?如何快速入门呢?