我有下面的xpath表达式
//div[@class="post-content"]//img它在html页面上运行,扫描图像。上面的查询返回了很多图像,但我只想要列表中的第二个图像。
我已经尝试过了,但没有成功:
//div[@class="post-content"]//img[1] and
//div[@class="post-content"]//img[position()=1]发布于 2012-04-05 16:37:05
在XPath中索引从1个位置开始,因此
//div[@class="post-content"]//img[2]如果您必须在div[@class="post-content"]中选择每个第2个img,则应该可以正常工作。如果必须从div[@class="post-content"]中的所有图像中仅选择第二个img,请使用:
(//div[@class="post-content"]//img)[2]发布于 2012-04-05 16:37:16
XPath中的索引是从1开始的,而不是从0开始。试一试
(//div[@class="post-content"]//img)[position()=2]https://stackoverflow.com/questions/10025221
复制相似问题