Scrapy-找到正确的CSS选择器

时间:2020-03-27 21:51:13

标签: python css scrapy

# -*- coding: utf-8 -*-
import scrapy
from ..items import LowesspiderItem


class LowesSpider(scrapy.Spider):
    name = 'lowes'
    #allowed_domains = ['lowes.com']
    start_urls = ['https://www.lowes.com/pd/ZLINE-KITCHEN-BATH-Ducted-Red-Matte-Wall-Mounted-Range-Hood-Common-42-Inch-Actual-42-in/1001440644']

    def parse(self, response):
        items = response.css('.grid-container')
        for product in items:
            item = LowesspiderItem()

        #get product price
            productPrice = product.css('.art-pd-price::text').getall()


            item["productPrice"] = productPrice


            yield item

这是我获得选择器的方式: enter image description here

enter image description here

在查看网站的html时,我仍然对如何找到正确的选择器感到困惑。我通过滚动到顶部并找到所有突出显示的项目来找到顶层项目。然后,我在Google chrome上使用CSS选择器扩展名来查找要抓取的特定元素。该程序应该给我回价,但我没有任何结果。任何帮助或指导将不胜感激!

1 个答案:

答案 0 :(得分:0)

因此您缺少商店的位置,因此只需添加位置cookie

相关问题