【发布时间】:2019-01-07 02:35:13
【问题描述】:
我正在尝试从这个 url https://www.farfetch.com/shopping/men/gucci-white-rhyton-web-print-leather-sneakers-item-12889013.aspx?storeid=9359 抓取一些数据
html 看起来像这样:
<div class="cdb2b6" id="bannerComponents-Container">
<p class="_41db0e _527bd9 eda00d" data-tstid="merchandiseTag">New Season</p>
<div class="_1c3e57">
<h1 class="_61cb2e" itemprop="brand" itemscope="" itemtype="http://schema.org/Brand">
<a href="/shopping/men/gucci/items.aspx" class="fd9e8e e484bf _4a941d f140b0" data-trk="pp_infobrd" data-tstid="cardInfo-title" itemprop="url" aria-label="Gucci">
<span itemprop="name">Gucci</span>
</a>
</h1>
</div>
</div>
我在scrapy shell中运行response.xpath('//div[@id="bannerComponents-Container"]/@class'),但我得到的是:
In [1]: response.xpath('//div[@id="bannerComponents-Container"]/@class')
Out[1]: []
为什么?我在 Amazon、Ebay 等上遇到了类似的问题,我的 xpath 选择器似乎不起作用
【问题讨论】:
-
我用 HTML 测试了表达式,它确实有效。所以错误很可能在其他地方。
-
@zx482 你认为它还能在哪里?我不知道如何解决这个问题
-
@darbulix,根据 SO 规则,您应该提供重现问题的代码。
-
@derloopkat 没有代码。我在 Scrapy shell 中运行它
标签: xpath web-scraping scrapy