我拉我的头发与示例语句。我的代码是这样的。在运算符不工作,因为我期望与字符串列表
Test2 = selector2.xpath('string(//div[@class="js-shipping-slide-panel shipping-slide-panel-section product-buying-table-row-alt"])').extract()
print "Test2", Test2
我得到的输出:
Test2 [u' Shipping not available \n Shipping This item is not available for shipping. \n']
这是完美的。所以这里是我的示例如果我试图陈述
if "shipping" in Test2:
print "Found it"
else:
print "It's Not There"
我得到的结果它不存在。我甚至复制的输出和硬编码的Test2是
Test2 = "u' Shipping not available \n Shipping This item is not available for shipping. \n'"
和if语句的运行同样和它的工作,让我的“发现”的结果。我在这里错过了什么?谢谢。
此外,我想使用Test2.lower,并说如果“运送不可用”,那么....等等......试图以任何顺序匹配所有3个单词或将它必须是一个完全匹配确切的顺序?谢谢。 – Nick
您的第一个示例输出是列表中的一个字符串,您的硬编码输出只是字符串。要检查示例输出中的字符串,您需要执行以下操作:'如果在Test2 [0]中运输“:'在字符串中检查而不是检查字符串'shipping'是否在列表中 – Marius