蜘蛛爬网0页

时间:2019-04-13 11:10:18

标签: python web-scraping scrapy

我需要从以下页面抓取所有价格和型号:

<li class="item col-sm-4 col-xs-6" product-id="156385" itemscope  itemtype="http://schema.org/Product">
    .....
      <span class="product-name" itemprop="name">35/139 Tokyo</span>
    .....
        <span class="model" itemprop="model">107-0001 BEKKO2</span>
    .....                   
           <span class="price" itemprop="price" content="2349.00">2 349 KČ            </span>
    ..
</li>

<li class="item col-sm-4 col-xs-6" product-id="13456" itemscope  itemtype="http://schema.org/Product">
    .....
      <span class="product-name" itemprop="name">35/139 Tokyo</span>
    .....
        <span class="model" itemprop="model"> Model 3 </span>
    .....                   
           <span class="price" itemprop="price" content="2459.00">2 459 KČ            </span>
    ..
</li>
....

以此类推,每个李都拥有这个品牌的典范。

我为此创建了一个蜘蛛类:

import scrapy

class EyreimSpider(scrapy.Spider):

    name = "eyerim"
    def start_requests(self):
        urls = [
            'http://eyerim.cz/brand/35-139-tokyo/'
        ]
        for url in urls:
            yield scrapy.Request(url=url, callback=self.parse)

    def parse(self, response):
        for models in response.css('li.item.col-sm-4.colxs-6'):  #holds all the models
            yield {
                #'product_name': models.css('span.product-name').get(),
                #'price': models.css('span.price::text').get().partition('K')[0].rstrip().replace(u'\xa0', u''),    
                'model' : models.css('span.model::text').extract(),
                'price':  models.css('span::attr(content)').extract()
            }           

但是当我运行Spider时,没有结果:

Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)

response.css表达式有效,我已经在草率的shell中尝试了所有这些表达式,并且返回了结果。建议???谢谢

1 个答案:

答案 0 :(得分:2)

据我所见,您的示例代码。您在CSS项目存储区中键入了colxs-6而不是col-xs-6
由于scrapy找不到类为colxs-6 -> EyreimSpider.parse方法的元素,因此无法检索数据