好的,所以我尝试将xpath选择的结果与一些字符串匹配,但是我认为我没有从选择中得到正确的结果。在
我的代码如下:
def parse_item(self, response):
for sel in response.xpath('//*[@id="tab:specificaties"]'):
category = sel.xpath('table/tbody/tr[2]/td[2]/a/text()').extract()
logging.warning(category)
if category == "Videokaarten":
logging.warning("Videokaart")
elif category == "Geheugen intern":
logging.warning("Geheugen")
elif category == "Moederborden":
logging.warning("Moederbord")
elif category == "Behuizingen":
logging.warning("Behuizing")
elif category == "Processors":
logging.warning("Processor")
elif category == "Voedingen":
logging.warning("Voeding")
elif category == "Processorkoeling":
logging.warning("Processorkoeling")
elif category == "Barebones":
logging.warning("Barebone")
因此,我要做的是检查类别是否与上面所述的字符串匹配,如果匹配,则进行相应的处理。日志记录只用于检查返回的category的值
^{pr2}$在我的候机楼。在
我希望有人能对这个案子有所了解。提前谢谢!在
通常,当您从xpath提取时,它会以列表形式返回结果,您可以尝试将
if ... ==
语句更改为if ... in ...:
,如下所示:希望这有帮助。在
相关问题 更多 >
编程相关推荐