xpath只适用于第一个imag

2024-06-28 11:03:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在抓取这个网站 http://www.propertyfinder.ae/en/buy/villa-for-sale-dubai-jumeirah-park-1849328.html?img/0

我想得到这个标记中的所有图像src div[@id='propertyPhoto']

我试过这个xpath

.//div[@id='propertyPhoto']//img/@src

我做了一个循环来提取src,但是我只得到了第一个图像src

请帮忙


Tags: 图像divsrcidhttpimgfor网站
1条回答
网友
1楼 · 发布于 2024-06-28 11:03:17

只有主图像在div#propertyPhoto中。其他的在li#propertyPhotoMini0li#propertyPhotoMini1。。。在

所以XPath应该稍加修改以匹配两者。id它们的属性都以propertyPhoto开头;可以使用以下XPath:

.//*[starts-with(@id, 'propertyPhoto')]//img/@src

示例:

^{pr2}$

输出:

http://c1369023.r23.cf3.rackcdn.com/1849328-1-wide.jpg
http://c1369023.r23.cf3.rackcdn.com/1849328-1-mini.jpg
http://c1369023.r23.cf3.rackcdn.com/1849328-2-mini.jpg
http://c1369023.r23.cf3.rackcdn.com/1849328-3-mini.jpg
http://c1369023.r23.cf3.rackcdn.com/1849328-4-mini.jpg
http://c1369023.r23.cf3.rackcdn.com/1849328-5-mini.jpg
http://c1369023.r23.cf3.rackcdn.com/1849328-6-mini.jpg
http://c1369023.r23.cf3.rackcdn.com/1849328-7-mini.jpg
http://c1369023.r23.cf3.rackcdn.com/1849328-8-mini.jpg
http://c1369023.r23.cf3.rackcdn.com/1849328-9-mini.jpg
http://c1369023.r23.cf3.rackcdn.com/1849328-10-mini.jpg

相关问题 更多 >