gpt4 book ai didi

python - 在lxml中的html注释之间选择div

转载 作者:数据小太阳 更新时间:2023-10-29 02:19:43 26 4
gpt4 key购买 nike

这是我的html文件

<div>
<div></div>
<div></div>
<!--Comment1-->
<div>1</div>
<div>2</div>
<div>3</div>
<!--Comment2-->
<div></div>
<div></div>
<div></div>
</div>

我想在评论 1 和评论 2 之间选择 div

有了这个 xPath = "/div/comment()"我可以选择 <!--Comment1--><!--Comment2-->

但是我要选择这个

   <div>1</div>
<div>2</div>
<div>3</div>

最佳答案

//*[preceding-sibling::comment() and following-sibling::comment()]

或更严格的版本:

//*[preceding-sibling::comment()[. = 'Comment1'] 
and following-sibling::comment()[. = 'Comment2']]

关于python - 在lxml中的html注释之间选择div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8050929/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com