If语句碎片xpath不工作

2024-10-04 01:23:03 发布

您现在位置:Python中文网/ 问答频道 /正文

好的,所以我尝试将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}$

在我的候机楼。在

我希望有人能对这个案子有所了解。提前谢谢!在


Tags: 字符串代码selfparseresponseloggingdefitem