with_contains 和 without_contains 的输出是什么

what is the output of with_contains and without_contains

with_contains 和 without_contains 的输出是什么,请解释包含,当我不使用包含时,会生成错误

exceptions.ValueError: Invalid XPath: //div[@class, "product-name"]"

#<div class="product-name">Adcor Defense BEAR 223 16 OPT RDY</div>

with_contains = hxs.select('//div[contains(@class, "product-name")]/text()').extract()
without_contains = hxs.select('//div[@class, "product-name"]/text()').extract()

您问题的答案很简单 - 包含字符串函数,用于检查值中的子字符串。例如:

..
<div class="product-name other_class">Example</div>

要从此元素获取数据:

data = hxs.select('//div[contains(@class, "product-name")]/text()').extract()

如果您不使用 contains 意味着 class 提供的值完全相等,您应该使用语法 @class="value ,在您的情况下:

exactly = hxs.select('//div[@class="product-name"]/text()').extract()