我拉我的頭髮與示例語句。我的代碼是這樣的。在運算符不工作,因爲我期望與字符串列表
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