[英]Unable to get all attribute(img @src) values using xpath selenium python
[英]I want to get the attribute value of @src using XPath in python
url = 鏈接
response.css("div.image-wrap.fff-pic img").xpath("@src").extract()
response.xpath("//div[@class='image-wrap fff-pic']/img/@src").extract()
但它無法提供屬性值。 output 與上述 XPath 沒有。 我需要從此頁面獲取 image_url。 我嘗試了不同的 XPath 表達式,但所有表達式都沒有結果。
要獲取所有圖像屬性,您必須使用正確的 XPath:
response.xpath("//div[@class='image-wrap']/img/@data-src").extract()
Output:
['https://i.dailymail.co.uk/1s/2020/04/26/01/27654346-8257569-image-a-12_1587860534559.jpg',
'https://i.dailymail.co.uk/1s/2020/04/26/01/27654344-8257569-Few_pieces_The_33_year_old_actor_wore_only_hot_pink_athletic_sho-a-55_1587861487279.jpg',
'https://i.dailymail.co.uk/1s/2020/04/26/01/26558472-8257569-Back_on_Shia_seems_to_have_reconciled_with_his_ex_Mia_Goth_pictu-a-56_1587861487300.jpg']
要獲得第一個,請使用:
response.xpath("(//div[@class='image-wrap'])[1]/img/@data-src").extract()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.