Scrapy编写未知深度的XPath表达式(Scrapy writing XPath expression for unknown depth)

编程入门 行业动态 更新时间:2024-10-24 08:31:39
Scrapy编写未知深度的XPath表达式(Scrapy writing XPath expression for unknown depth)

我有一个html文件,如:

<div id='author'> <div> <div> ... <a> John Doe </a>

我不知道作者div下会有多少div。 它可能具有不同页面的不同深度。

那么这种xml的XPath表达式是什么?

顺便说一句,我试过:

//div[@id = "author"]/*/a/text()

但这似乎只适用于作者div的孙子。

I have an html file which is like:

<div id='author'> <div> <div> ... <a> John Doe </a>

I do not know how many div's would be under the author div. It may have different depth for different pages.

So what would be the XPath expression for this kind of xml?

By the way, I tried:

//div[@id = "author"]/*/a/text()

but this only seems to work for grandchildren of the author div.

最满意答案

使用双斜杠在div元素内的任何位置找到一个id="author"元素:

//div[@id = "author"]//a/text()

Use double slash to find an a element anywhere inside the div element with id="author":

//div[@id = "author"]//a/text()

更多推荐

本文发布于:2023-08-05 19:23:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1437859.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表达式   深度   XPath   Scrapy   depth

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!