【发布时间】:2015-03-11 05:50:12
【问题描述】:
问题看起来与XPath Get first element of subset 相同,但我认为它有点不同。
以下是博客: http://www.mademoiselledeco.com/
我想获取每个帖子的第一张照片。为此,我想到了以下 xpath 查询:
//div[contains(@class,'type-post status-publish')]//img/@src
按照我提到的上一篇文章的例子,我也尝试了:
//div[contains(@class,'type-post status-publish')](//img/@src)[1]
但那是说
警告:DOMXPath::query():无效的表达式
有什么想法吗?
非常感谢
【问题讨论】:
-
这个
//div[contains(@class,'type-post status-publish')]//img[1]/@src不起作用? -
不,不幸的是,它似乎占用了每个帖子的所有 img 元素。我想要做的是只获得 img 标签的第一次出现