【问题标题】:Scrapy returning empty lists when using css使用css时Scrapy返回空列表
【发布时间】:2020-05-02 07:44:28
【问题描述】:

我正在尝试抓取 nordstrom 产品说明。我得到了所有的项目链接(存储在本地 mongodb 数据库中),现在正在遍历它们,这是一个示例链接 https://www.nordstrom.ca/s/leith-ruched-body-con-tank-dress/5420732?origin=category-personalizedsort&breadcrumb=Home%2FWomen%2FClothing%2FDresses&color=001

我的蜘蛛代码是:

def parse(self, response):
    items = NordstromItem()
    description = response.css("div._26GPU").css("div::text").extract()
    items['description'] = description
    yield items

我也试过scrapy shell,返回的页面是空白的。 我也在使用scrapy随机代理。

【问题讨论】:

  • “我也试过scrapy shell,返回的页面是空白的”。听起来您被检测为机器人并给出了错误的响应。这就是您需要首先解决的问题。

标签: scrapy


【解决方案1】:

我建议您使用 css 或 xpath 选择器来获取您想要的信息。这里有更多关于它的信息:https://docs.scrapy.org/en/latest/topics/selectors.html

您还可以使用 css/xpath 检查器来帮助确定选择器是否获得了您想要的信息。喜欢这个 Chrome 扩展:https://autonomiq.io/chropath/

【讨论】:

    猜你喜欢
    • 2021-12-20
    • 2019-06-26
    • 1970-01-01
    • 2021-11-24
    • 2020-11-14
    • 1970-01-01
    • 2018-02-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多