我不能用scrapy提取这个网址

问题描述 投票:1回答:1

嗨,我试图提取url imagen与xpath。我已经xpathHelper扩展在chromeHtml。

<source src="https://estaticos.test.com/test/117/452/img1.jpg">

在scrapy我尝试这个

ml_item['img2'] = response.xpath(
        '//*/picture/source[2]/@src').extract()

并尝试

ml_item['img2'] = response.xpath(
        '/html/body/div/div/div/div[1]/main/div/div[1]/div[2]/div[1]/picture/img[1]').extract()

但不工作,返回空,在xpathhelper中返回正确的url。使用其他图片的url,我没有得到任何问题。ml_item['image_urls'] = response.xpath( '//*[contains(@class,"detail-gallery")]/div/div/div/img/@src').extract()而它的工作

我用的是chrome和firefox

python xpath scrapy
1个回答
0
投票

嗨,试试使用这个Xpath表达式。

(/picture[@class='image-wrapper']img)[1]@src


0
投票
response.xpath('//*[@class="main-info"]//img[@class="image"]/@src').extract_first()
© www.soinside.com 2019 - 2024. All rights reserved.