首页 > 解决方案 > 使用 \n 和空格查找类名的 xpath

问题描述

这可能是一个简单的问题,我是新手。

我正在尝试获取此 div 中的数据

<div class="search-results-listings
        " vocab="http://schema.org/" typeof="SearchResultsPage">

response.xpath("//div[@class='search-results-listings\n']") 和 response.xpath("//div[@class='search-results-listings\n ']") 是返回空数组

标签: xpathscrapy

解决方案


您可以使用XPath's contains

response.xpath("//div[contains(@class, 'search-results-listings')]")

推荐阅读