cra草的文字解压缩不正确

时间:2019-11-08 16:29:23

标签: scrapy

我有问题。

我想在网站上获得一条文字(价格)。诸如标题/名称之类的所有其他东西都起作用,但价格不起作用。

price = product.css('.offerList-item-priceWrapper .priceRange::text')[0].extract().replace('ab','').replace('*','').replace('\xc2','').replace('\xa0','').replace('€','').strip()

那就是价格呼叫...

那是html网站

<div class="offerList-item-priceWrapper">
        <div class="offerList-item-pricePrefix">
                        <span></span>
                        <span class="offerList-item-pricePrefixCount">62 Angebote</span>
                    </div>
                    <div class="priceRange">
                        <span class="priceRange-from">
                            <span class="price-from">
                                ab</span>
                            <span class="price-currencySymbol price-currencySymbol--before">€</span>
                            30,82<span class="price-currencySymbol price-currencySymbol--after">&nbsp;€</span>
                        </span>
                        <span class="priceRange-to">
                            <span class="price-currencySymbol price-currencySymbol--before">€</span>
                            126,61<span class="price-currencySymbol price-currencySymbol--after">&nbsp;€</span>
                        </span>
                    </div>
                </div>

您不能说确实有很多空格... 如果我打印价格,我只会得到空白。

我在此处放置了一个屏幕截图,在那里您可以看到chrome please check here的控制台

我认为空格太多,在该示例中我没有得到30,82 ...

1 个答案:

答案 0 :(得分:0)

我设法为您简化了很多。

pricerange-from = product.css('div.priceRange span.priceRange-from::text').getall()[2].strip()
pricerange-to = product.css('div.priceRange span.priceRange-to::text').getall()[1].strip()

更多使用选择器的实践。希望这个答案能告诉您您哪里出了错。